2016-05-30 60 views
0

AngularJS我們的工作很多有承諾,我想知道是否有某種方式來手動手動設置承諾的結果(無論是成功與否),而不rejectresolveAngularJS - 設定承諾手動

喜歡的東西

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; 
     }  
    } 
} 
+1

如果您不打算使用手動方法'resolve'和'reject',手動設置是什麼意思?你試圖解決的更高層次的問題是什麼? – charlietfl

回答

0

擺弄了一會我找到了答案後,我不得不使用resolve /在延遲根級別拒絕功能。

list[i].defer.resolve(response);