davej / angular-classy

Cleaner class-based controllers with Angular 1
http://davej.github.io/angular-classy/
813 stars 27 forks source link

Doesn't work with ngTable #14

Closed imevro closed 10 years ago

imevro commented 10 years ago

Hello! Thanks for your module.

When I try inject ngTableParams (factory in ngTable), angular says ReferenceError

Uncaught ReferenceError: ngTableParams is not defined

My controller:

angular.module('remark').classy.controller
  name: 'ListCtrl'

  inject: ['$scope', 'ngTableParams']

  _data: [{name: "Moroni", age: 50},
    {name: "Tiancum", age: 43},
    {name: "Jacob", age: 27},
    {name: "Nephi", age: 29},
    {name: "Enos", age: 34},
    {name: "Tiancum", age: 43},
    {name: "Jacob", age: 27},
    {name: "Nephi", age: 29},
    {name: "Enos", age: 34},
    {name: "Tiancum", age: 43},
    {name: "Jacob", age: 27},
    {name: "Nephi", age: 29},
    {name: "Enos", age: 34},
    {name: "Tiancum", age: 43},
    {name: "Jacob", age: 27},
    {name: "Nephi", age: 29},
    {name: "Enos", age: 34}];

  customersTable: new ngTableParams(
    page: 1
    count: 10
  ,
    total: data.length
    getData: ($defer, params) ->
      $defer.resolve _data.slice((params.page() - 1) * params.count(), params.page() * params.count())
      return
  )

CoffeeScript; AngularJS 1.2.16, ngTable 0.3.1

davej commented 10 years ago

I'm not sure how ngTable works but I presume that you would like to do something similar to this:


angular.module('remark').classy.controller
  name: 'ListCtrl'

  inject: ['$scope', 'ngTableParams']

  init: ->
    data = [{name: "Moroni", age: 50},
      {name: "Tiancum", age: 43},
      {name: "Jacob", age: 27},
      {name: "Nephi", age: 29},
      {name: "Enos", age: 34},
      {name: "Tiancum", age: 43},
      {name: "Jacob", age: 27},
      {name: "Nephi", age: 29},
      {name: "Enos", age: 34},
      {name: "Tiancum", age: 43},
      {name: "Jacob", age: 27},
      {name: "Nephi", age: 29},
      {name: "Enos", age: 34},
      {name: "Tiancum", age: 43},
      {name: "Jacob", age: 27},
      {name: "Nephi", age: 29},
      {name: "Enos", age: 34}];

    @$scope.customersTable = new @ngTableParams(
      page: 1
      count: 10
    ,
      total: data.length
      getData: ($defer, params) ->
        $defer.resolve _data.slice((params.page() - 1) * params.count(), params.page() * params.count())
        return
    )