这是我的代码:
界面
export interface IConsignmentDataService {
getConsignmentListData(): ng.IPromise<IConsignmentListViewModel>;
filterConsignments(filters: Filter[]): ng.IPromise<IConsignmentListViewModel>;
}
实施
export class ConsignmentDataService implements IConsignmentDataService {
static $inject: string[] = ["$http", "$q"];
constructor(private $http: ng.IHttpService, private $q: ng.IQService) {
}
getConsignmentListData(): ng.IPromise<IConsignmentListViewModel> {
var defer = this.$q.defer();
var apiUrl = "/Api/Consignments/AllConsignments";
this.$http.get(apiUrl)
.success((data: IConsignmentListViewModel) => {
defer.resolve(data);
})
.error((reason: string) => {
defer.reject(reason);
});
return defer.promise;
}
filterConsignments(filters: Filter[]): ng.IPromise<IConsignmentListViewModel> {
var defer = this.$q.defer();
var url = "/Api/Consignments/FilterConsignments";
this.$http.post(url, { "filters": filters })
.success((data: IConsignmentListViewModel) => {
defer.resolve(data);
})
.error((reason: string) => {
defer.reject(reason);
});
return defer.promise;
}
}
这就是我所说的:
refresh(): void {
this.consignmentDataService.filterConsignments(this.currentFilters).then((data: IConsignmentListViewModel) => {
console.log("success");
}, () => {
console.log("failure");
});
}
问题是,当我致电getConsignmentListData()
时它正常工作但是当我致电filterConsignments
时给出错误:
错误:this.consignmentDataService.filterConsignments不是函数
请确保解决方案正确构建,并且参数也很好地填充。我还尝试在console.log()
内使用filterConsignments
来检查它是否被调用但没有运气。它总是给出错误。
详细错误消息:
Error: this.consignmentDataService.filterConsignments is not a function
ConsignmentListController.prototype.refresh@http://localhost:8044/app/consignment/List/consignmentList.controller.js:145:21
ConsignmentListController@http://localhost:8044/app/consignment/List/consignmentList.controller.js:139:21
invoke@http://localhost:8044/Scripts/angular.js:4478:14
instantiate@http://localhost:8044/Scripts/angular.js:4486:27
$ControllerProvider/this.$get</<@http://localhost:8044/Scripts/angular.js:9151:18
ngViewFillContentFactory/<.link@http://localhost:8044/Scripts/angular-route.js:977:26
invokeLinkFn@http://localhost:8044/Scripts/angular.js:8789:9
nodeLinkFn@http://localhost:8044/Scripts/angular.js:8289:1
compositeLinkFn@http://localhost:8044/Scripts/angular.js:7680:13
publicLinkFn@http://localhost:8044/Scripts/angular.js:7555:30
createBoundTranscludeFn/boundTranscludeFn@http://localhost:8044/Scripts/angular.js:7699:1
controllersBoundTransclude@http://localhost:8044/Scripts/angular.js:8316:18
update@http://localhost:8044/Scripts/angular-route.js:935:25
$RootScopeProvider/this.$get</Scope.prototype.$broadcast@http://localhost:8044/Scripts/angular.js:16311:15
commitRoute/<@http://localhost:8044/Scripts/angular-route.js:619:15
processQueue@http://localhost:8044/Scripts/angular.js:14745:28
scheduleProcessQueue/<@http://localhost:8044/Scripts/angular.js:14761:27
$RootScopeProvider/this.$get</Scope.prototype.$eval@http://localhost:8044/Scripts/angular.js:15989:16
$RootScopeProvider/this.$get</Scope.prototype.$digest@http://localhost:8044/Scripts/angular.js:15800:15
$RootScopeProvider/this.$get</Scope.prototype.$apply@http://localhost:8044/Scripts/angular.js:16097:13
done@http://localhost:8044/Scripts/angular.js:10546:36
completeRequest@http://localhost:8044/Scripts/angular.js:10744:7
requestLoaded@http://localhost:8044/Scripts/angular.js:10685:1
<div data-ng-animate="1" class="ng-scope" ng-view="">