功能 / Class 作为 Angular 服务
Function / Class as Angular service
我正在尝试在 Angular 个控制器上注入寻呼服务,所以我有:
angular.module("app").factory("paging", paging);
function paging() {
var paging = function (pageNumber, pageSize, itemCount) {
this.itemCount = itemCount;
this.pageNumber = pageNumber;
this.pageSize = pageSize;
this.pageCount = itemCount > 0 ? Math.ceil(itemCount / pageSize) : 0;
}
paging.prototype.itemCount = 1
paging.prototype.pageCount = 1
paging.prototype.pageNumber = 1
paging.prototype.pageSize = 1
paging.prototype.isFirst = function () {
return this.pageNumber === 1;
}
paging.prototype.toFirst() = function () {
this.pageNumber = 1;
}
return paging;
}
我一直收到错误 "paging.prototype.toFirst is not a function"。
我做错了什么?
它抛出一个错误,因为你在创建它之前调用了 toFirst
函数,我可以说它的语法错误。您应该创建函数而不是调用它。
paging.prototype.toFirst = function () {
this.pageNumber = 1;
}
我正在尝试在 Angular 个控制器上注入寻呼服务,所以我有:
angular.module("app").factory("paging", paging);
function paging() {
var paging = function (pageNumber, pageSize, itemCount) {
this.itemCount = itemCount;
this.pageNumber = pageNumber;
this.pageSize = pageSize;
this.pageCount = itemCount > 0 ? Math.ceil(itemCount / pageSize) : 0;
}
paging.prototype.itemCount = 1
paging.prototype.pageCount = 1
paging.prototype.pageNumber = 1
paging.prototype.pageSize = 1
paging.prototype.isFirst = function () {
return this.pageNumber === 1;
}
paging.prototype.toFirst() = function () {
this.pageNumber = 1;
}
return paging;
}
我一直收到错误 "paging.prototype.toFirst is not a function"。
我做错了什么?
它抛出一个错误,因为你在创建它之前调用了 toFirst
函数,我可以说它的语法错误。您应该创建函数而不是调用它。
paging.prototype.toFirst = function () {
this.pageNumber = 1;
}