title: AngularJS ng-table cannot set property '$data' of null
body: <p>I've just started using ng-table and I'm trying to test it through jasmine unit tests (not sure if this is the best way to test my controllers) and I keep running into this error;</p>
  
  <pre><code>TypeError: Cannot set property '$data' of null
      at project/vendor/assets/javascripts/ng-table-0.3.1/ng-table.src.js:396:55
      at C (project/vendor/assets/javascripts/angular-min.js:92:375)
      at project/vendor/assets/javascripts/angular-min.js:94:28
      at h.$eval (project/vendor/assets/javascripts/angular-min.js:102:308)
      at h.$digest (project/vendor/assets/javascripts/angular-min.js:100:50)
      at h.$apply (project/vendor/assets/javascripts/angular-min.js:103:100)
      at f (project/vendor/assets/javascripts/angular-min.js:67:98)
      at handleResponse (project/vendor/assets/javascripts/angular-mocks.js:1160:9)
      at Function.$httpBackend.flush (project/vendor/assets/javascripts/angular-mocks.js:1491:26)
      at null.&lt;anonymous&gt; (project/spec/javascripts/unit/debtors_controller_spec.js.js:50:24)
  </code></pre>
  
  <p>Here is where I setup the ngTableParams in my controller</p>
  
  <pre><code>  # Setup ng-table with defaults and data
    $scope.tableParams = new ngTableParams({
      page: 1,
      count: 10,
      sorting: { code: 'asc'}
    }, {
      # data is created by ngTableParams
      total: 0,
  
      # ng-table will ask for updated data, this is where it gets it from.
      getData: ($defer, params) -&gt;
        # Go get a list of debtors
        Debtor.query {}, (data) -&gt;
          # Once successfully returned from the server with my data process it.
          params.total(data.length)
  
          # Filter
          filteredData = (if params.filter then $filter('filter')(data, params.filter()) else data)
  
          # Sort
          orderedData = (if params.sorting then $filter('orderBy')(filteredData, params.orderBy()) else data)
  
          # Paginate
          $defer.resolve(orderedData.slice((params.page() - 1) * params.count(), params.page() * params.count()))
    })
  </code></pre>
  
  <p>Here is the jasmine test</p>
  
  <pre><code>  # ================================================================================
    # Delete tests
    # ================================================================================
    describe "destroy", -&gt;
      beforeEach(inject ( ($controller, $rootScope, $location, $state, $httpBackend) -&gt;
        ctrl = $controller('DebtorsController', {
          $scope: @scope,
          $location: $location
        })
      ))
  
      it "gets new listing", -&gt;
        @scope.debtors = [{id: 1, name: "Good guys"}, {id: 2, name: "John"}]
        @httpBackend.whenDELETE('/clients/1').respond(200)
        @httpBackend.whenGET('/debtors').respond(200,  [{name: "John"}])
        @scope.destroy(1)
        @httpBackend.flush()
        expect(@scope.debtors[0].name).toEqual('John')
  </code></pre>
  
  <p>Here is my code for deleting (which works)</p>
  
  <pre><code>  # --------------------------------------------------------------------------------
    # Delete
    # --------------------------------------------------------------------------------
    $scope.destroy = (id) -&gt;
      Client.delete
        id: id
      , (response) -&gt;             # Success
        flash("notice", "Client deleted", 2000)
        $scope.tableParams.reload() # Reload ng-table data, which will get a new listing from the server.
      , (response) -&gt;             # Failure
  </code></pre>