我怎样才能确保complete()
无论 $http 调用的结果如何,函数都会使用 Angular.js 提供的 Promise API 运行吗?
$http({
method: 'POST',
url: submitUrl,
data: $scope.data
})
.success(function(data) {
// execute this code on success
})
.error(function(data) {
// execute this code on error
})
.complete(function() {
// execute this code regardless of outcome
});
请求完成后,可以使用它来隐藏 AJAX 旋转器图标。无论请求结果如何,您都希望隐藏微调器。
我不是世界上最伟大的 Angular.js 专家,但我知道你可以执行以下操作:
whatever.then(function() {
// success code here
}, function() {
// error code here
return true; // return anything that's not undefined (and not a `throw()`) to force the chain down the success path at the following then().
}).then(function() {
// "complete" code here
});
你基本上被迫从一个或多个方面设计出一些东西.then()
,这是 $q Promise 的唯一方法。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)