【发布时间】:2016-01-10 13:30:30
【问题描述】:
我已经更改了我的 url 的 env 属性以在本地测试我的代码。似乎错误回调甚至没有被调用。 我的代码 sn-p-
$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--> Always this line of code is executing..
);
};
如果我尝试编写其他错误函数。它甚至没有被调用。
$scope.getfiles = function(){
Api.flatFile.query().$promise.then(
function(result){ $scope.File = result;
},
function (result) { // this block is not getting called
if(result.status== 404){
$scope.addErrorAlert("Service is down.Please try again later",true);
return;
}
});
};
有人可以帮我解决这种情况吗?
FileServices.factory('Api', ['$res', '$loc',
function($res, $loc){
var contextPath = $loc.absUrl().split('/app/')[0];
return {
flatFile: $res(contextPath+'/app/config/flatFile/data', {}, {
query: {method:'GET', isArray:true},
save: {method:'POST'},
})
};
}]);
【问题讨论】:
-
您能否通过开发者控制台验证该函数是否被调用或未对其进行调试。控制台是否有任何错误>
-
角度承诺库是
$q -
API.file.query()是什么,你想用它实现什么,请提供代码部分。 -
请看我编辑的帖子..
-
API 是一项服务。并尝试在服务关闭时添加错误警报消息。所以在本地我试图改变 url 的 env 属性。
标签: javascript angularjs angularjs-directive angularjs-scope angular-ui-router