【发布时间】:2016-11-23 03:15:24
【问题描述】:
我使用的是旧版本的 ng-tables 0.4.2,如果我升级到 0.4.3,它会在我的 chromium 控制台中显示错误
TypeError: undefined is not a function
at reload (http://localhost:3000/assets/ng-table/ng-table.min.js?body=1:140:160)
at Object.fn (http://localhost:3000/assets/ng-table/ng-table.min.js?body=1:196:24)
at Scope.$digest (http://localhost:3000/assets/angular/angular.js?body=1:5226:31)
at Scope.$apply (http://localhost:3000/assets/angular/angular.js?body=1:5305:28)
at done (http://localhost:3000/assets/angular/angular.js?body=1:3182:26)
at completeRequest (http://localhost:3000/assets/angular/angular.js?body=1:3306:9)
at XMLHttpRequest.xhr.onreadystatechange (http://localhost:3000/assets/angular/angular.js?body=1:3279:13)
这是我配置 tableParams 的方式
page = $location.search()['page'] # Get page from the URL
# data is created by ngTableParams
$scope.tableParams = new ngTableParams({
page: if page then page else 1,
count: 10,
sorting: { invoice_no: 'desc'}
}, {
total: 0,
filterDelay: 500,
# ng-table will ask for updated data, this is where it gets it from.
getData: ($defer, params) ->
# Go get a list of debtors
Invoice.query params.url(), (data) ->
params.total($scope.total)
$location.search(params.url()) # Params into URL
orderedData = (if params.sorting then $filter('orderBy')(data, params.orderBy()) else data) # Sort
$defer.resolve(orderedData) # Paginate / update table with new data
})
我确实在我的模块中包含 ng-tables,在我的控制器中包含 ngTableParams。
更新:传递模拟数据有效
如果我执行以下操作,则没有错误。
# ng-table will ask for updated data, this is where it gets it from.
getData: ($defer, params) ->
$defer.resolve([{invoice_no: 1}])
更新:使用 Restangular 代替 angular-resource 有效
所以使用 Restangular 进行查询工作
getData: ($defer, params) ->
Restangular.all('invoices').getList()
.then((data) ->
return data
)
也许在 ng-table 0.4.3 及更高版本中我不能再使用角度资源?或者我只是做错了。这是我的发票资源(在 ng-table 0.4.2 中工作)。
Invoice = ['$resource', 'apiPrefix', ($resource, apiPrefix) ->
$resource( apiPrefix + "/invoices/:id",
id: "@id"
,
# Add update method
update: {method: "PUT"}
)
]
angular
.module('paisApp')
.factory('Invoice', Invoice)
【问题讨论】:
标签: angularjs coffeescript ngtable