我有一個變量this.eligible
,我想分配給返回的承諾,而不是實際的承諾對象的值。
userService
this.eligible = this.sweepstakesService.checkUser(data);
sweepstakesService
checkUser({profileId}) {
var deferred = this.$q.defer();
var id = profileId.replace(/[{}]/g, "");
this.$q.when(this.getGuid(id)
.then(guid => this.determineEligibility(guid))
.catch(this.handleError))
.then(function(data){
deferred.resolve(data);
});
return deferred.promise;
}
getGuid(profileId){
return this.resourcesService.guid.save({id:profileId}).$promise.then(data => data.guid);
}
determineEligibility(response){
return this.resourcesService.eligibility.save({id:response}).$promise.then(data => data.isEligible);
}
handleError(response){
console.log(response);
}
目前我回國Promise{$$state: Object}
,而不是實際的解析值。
爲例目前尚不清楚你的要求。 ''我有一個變量''_What_變量? – sdgluck
我修改了我的問題 – byrdr