我的应用程序中有这个代码:
putTestQuestionResponses()
.finally(() => processingPutTestQuestion = false);
putTestQuestionResponses()返回一个promise。
我有没有办法让它成为“
答案 0 :(得分:3)
你可以这样做:
putTestQuestionResponses().then(
//resolved
function(){
processingPutTestQuestion = false;
},
//rejected
funciton(){
$timeout(function(){
processingPutTestQuestion = false
}, 30000);
}
);
记得注入$ timeout
答案 1 :(得分:1)
您可以使用.then
块来解决承诺。如下所示:
如果您收到来自AJAX电话的回复:
getResponsePromise.then(function(data){
//this is the success case where the response is resolved
processingPutTestQuestion = false ;
}, function(err){
//this is the error block
$timeout( function() {
processingPutTestQuestion = false ;
}, 30000)
});