【发布时间】:2015-11-21 16:55:19
【问题描述】:
我有以下代码:(我尝试了很多方法)
performLogin = (data: LoginRequest) => {
var deferred = this.qService.defer();
var response = this.httpService.get(
myServiceURL + '&' + ObjecttoParams(data))
.then(function (response) {
debugger;
this.loginResponse = JSON.parse(JSON.stringify(response.data));
});
debugger;
deferred.resolve(response);
debugger;
return(this.loginResponse);
}
这是我的这个服务的构造函数:
constructor($http: ng.IHttpService, $location: ng.ILocationService, $q: ng.IQService) {
this.qService = $q;
this.httpService = $http;
this.locationService = $location;
this.loginResponse = new LoginResponse();
this.serviceURL = staticURL + currentServiceName;
}
我正在调用我的控制器中的 performLogin,他们希望收到一个“LoginResponse”类,但是因为 .then() 稍后发生,所以我的“return this.loginResponse) 发生在 .then() 之前调用。
如何让他在返回之前等待 .then() 完成?
【问题讨论】:
标签: angularjs asynchronous typescript