我正在向我的API发出请求,我正在使用AngularJS $资源模块.它与$ http不同,所以我不知道如何处理我的错误.
我的服务:
var appServices = angular.module('app.services', ['ngResource']);
appServices.factory('Category', ['$resource',
function($resource){
return $resource('/apicategoryerr/?format=:format', {}, {
query: {
method: 'GET',
params: { format: 'json'},
isArray: true,
}
});
}]);
Run Code Online (Sandbox Code Playgroud)
我的控制器:
...
Category.query(function(data) {
console.log(data);
});
...
Run Code Online (Sandbox Code Playgroud)
我想要这样的东西或..如果我的API无效,我不知道如何处理错误..
Category.query().success(function() {
console.log('success');
}).error(function() {
console.log('error');
});
Run Code Online (Sandbox Code Playgroud) 使用ngResource在AngularJS 1.2rc(X),我怎么现在得到了状态代码?
RestAPI.save({resource}, {data}, function( response, responseHeaders ) {
});
Run Code Online (Sandbox Code Playgroud)
哪里RestAPI是我的ngResource.
响应具有$promise从服务器返回的对象和资源,但不再具有状态.responseHeaders()如果服务器将状态代码注入头对象,但该函数仅返回真实的返回状态代码,则该函数仅具有状态.所以有些服务器可能会提供服务,而有些服