我已经编写了一个带有take参数的服务,它在此基础上用http请求的响应来响应我。
this.getPaymentDueDetails=function(date){
this.getfromRemote('paymentdue/'+btoa(date))
.success(function(response){
return response;
})
.error(function(response){
return false;
})
}
getfromRemote
是我的另一项服务,它使http
请求
现在我正试图在我的控制器功能中获得这个服务调用的响应
$scope.callDueReports=function(blockNum){
var data;
data=myAngService.getPaymentDueDetails('2015-04-20');
console.log(data);
}
很明显,当页面最初加载时,我不会在数据中得到任何东西,但我希望getPaymentDueDetails的结果在其中。
请修改您的服务以返回如下承诺。
this.getPaymentDueDetails = function(date) {
return this.getfromRemote('paymentdue/' + btoa(date));
};
在控制器中检查承诺是否得到解决。
$scope.callDueReports = function(blockNum) {
var data;
myAngService.getPaymentDueDetails('2015-04-20').then(function(dataFromService) {
data = dataFromService;
console.log(data);
})
.catch(function(response) {
console.error('error');
});
};