【发布时间】:2014-03-14 20:52:59
【问题描述】:
请看演示here
function get(url) {
return $http.get(url)
.then(function(d){
return d.data
},
function(err){ //will work without handling error here, but I need to do some processing here
//call gets here
//do some processing
return err
})
}
get('http://ip.jsontest.co')
.then(function(response){
$scope.response = "SUCCESS --" + JSON.stringify(response);
}, function(err){
$scope.response = "ERROR -- " + err;
})
我有一个库函数get,它返回一个承诺。我正在那里处理错误,并将其返回(我在其中评论了 //do some processing )。我期待在客户端,它调用错误/失败处理程序。而是打印"SUCCESS --" + error
我可以使用 $q 和 reject 来完成这项工作,但有没有办法没有?
【问题讨论】:
标签: javascript angularjs promise