Angularjs 当承诺被拒绝时,Angular.js
这里是我的代码片段-Angularjs 当承诺被拒绝时,Angular.js,angularjs,angularjs-directive,angularjs-scope,angularjs-ng-repeat,Angularjs,Angularjs Directive,Angularjs Scope,Angularjs Ng Repeat,这里是我的代码片段- $scope.getfiles = function() { Api.file.query().$promise.then( function(result){ $scope.getfiles = result; }, //on success $scope.commonAjaxErrorHandling("Failed to get File data.", true) //on failure ); }; 我的疑问是,当承诺本身失败时(当
$scope.getfiles = function() {
Api.file.query().$promise.then(
function(result){ $scope.getfiles = result; }, //on success
$scope.commonAjaxErrorHandling("Failed to get File data.", true) //on failure
);
};
我的疑问是,当承诺本身失败时(当url不正确或服务器关闭时),那么我应该在哪里写这行代码
$scope.addErrorAlert("Service is down.Please try again later",true);
.catch(函数(e){
$scope.addErrorAlert(“服务已关闭,请稍后再试”,true);
})
您也可以根据需要使用
e
参数。这必须起作用:
$scope.getfiles = function() {
Api.file.query().$promise.then(
function(result){
$scope.getfiles = result; //on success
}
).catch(err){
$scope.commonAjaxErrorHandling("Failed to get File data.", true) //on failure
}