在我的控制器中,我有两个ajax服务:
inspectionReviewServices.getValue($scope.object.Id).then(function (result) {
$scope.inspectionReviews = result.data;
$scope.inspectionReviewsOriginal = angular.copy(result.data);
}, function (err) {});
damageEventServices.getValuesByInspReviews($scope.inspectionReviews).then(function (result) {
$scope.damageEvants = result.data;
})
加载页面时触发的http服务。
第一项服务被解雇inspectionReviewServices
,第二项服务被damageEventServices
。
问题是当damageEventServices
触发参数$scope.inspectionReviews
是undefined
,因为http服务是非同步的,并且未收到inspectionReviewServices
中的承诺。
所以我的问题是如何在damageEventServices
收到承诺后才触发此inspectionReviewServices
服务?
答案 0 :(得分:2)
inspectionReviewServices.getValue($scope.object.Id).then(function (result) {
$scope.inspectionReviews = result.data;
$scope.inspectionReviewsOriginal = angular.copy(result.data);
damageEventServices.getValuesByInspReviews($scope.inspectionReviews).then(function (damageResult) {
$scope.damageEvants = damageResult.data;
})
}, function (err) {});
在独立决议中调用依赖者。
答案 1 :(得分:0)
信守承诺:
promiseReturningService1().then(function(result) {
//resolved
promiseReturningService2(result).then(successCallBack, errorCallBack);
//etc.. etc.. etc...
}, function(error) {
//rejected
});
//code below this will not wait for the promise executions
alert("hello, I didn't wait!");