davej / angular-classy

Cleaner class-based controllers with Angular 1

Home Page:http://davej.github.io/angular-classy/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Doesn't work with ngTable

imevro opened this issue · comments

commented

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

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
    )