我已经更改了url的env属性,以便在本地测试我的代码。。错误回调似乎甚至没有被调用。我的代码片段-
$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'},
})
};
}]);
将您的代码更改为下面的代码,并告诉我们它是否有效。我不明白你为什么在那里使用$promise
?
$scope.getfiles = function() {
// This service's function returns a promise
Api.flatFile.query()
.then(function(data) {
// promise fulfilled
}, function(error) {
// promise rejected, could log the error with: console.log('error', error);
});
};