0
在AngularJS
我们的工作很多有承诺,我想知道是否有某种方式来手动手动设置承诺的结果(无论是成功与否),而不reject
和resolve
AngularJS - 设定承诺手动
喜欢的东西
var list = [];
function call(){
async()
.then(function(response){
console.info('yay');
})
.catch(function(error){
console.info('nay');
});
}
function async(){
var item = {
id: 1,
defer: $q.defer()
};
list.push(item);
sendRequestToAsyncService(item.id);
return item.defer.promise;
}
function receiveDataFromAsyncService(data, id){
for(var i = 0; i < list.length; i++){
if(id === list[i].id){
list[i].defer.promise = data;
}
}
}
如果您不打算使用手动方法'resolve'和'reject',手动设置是什么意思?你试图解决的更高层次的问题是什么? – charlietfl