【发布时间】:2015-08-21 11:26:43
【问题描述】:
我有一个使用 typescript 和 AngularJS 的服务代码,如下所示:
/// <reference path='../_all.ts' />
module bankApp {
'use strict';
export class MDCurrencyService implements IMDCurrencyService {
httpService: ng.IHttpService;
promise: ng.IPromise<void>;
constructor($http: ng.IHttpService,
$q : ng.IQService) {
this.httpService = $http;
}
get(): MDCurrency[] {
var promise = this.httpService.get('/Master/CurrencyGetAll').then(function (res) {
return res.data;
});
return promise;
}
save(cur: MDCurrency) {
this.httpService.post('/Master/CurrencySave', cur);
}
softDelete(id: string)
{ }
hardDelete(id: string)
{ }
}
}
我会这样使用我的控制器:
this.currencies = $scope.currencies = mdCurrencyService.get();
如何使用打字稿制作角度服务 $http? 我希望我的控制器中的 this.currencies 将填充来自服务器的数据。
【问题讨论】:
标签: angularjs typescript