在 Angular 中是否有捕获有关连接问题的错误的好方法?
服务 $http POST:
dossierService.getDossier(uid)
.then(function (result) {
vm.dossier = result.dossier;
}, function (error) {
handleError(error)
});//end dossierService.getDossier(uid)
如果存在连接问题,它将返回错误:
POST http://192.168.25.1:8080/api/query net::ERR_CONNECTION_TIMED_OUT
我如何向用户显示正确的消息,让他/她知道确切的错误是什么?
最佳答案
$http.post("/path", {data:"data"}).then(function(response){
// do something with success response
}).catch(function(error) {
console.log(JSON.stringify(error));
$scope.myerror=error
});
在你看来......
<div ng-if="myerror!=null">
{{myerror}} OR {{myerror.message}}
</div>
关于javascript - 正确处理 $http 调用 AngularJS 中的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34895358/