我有一个Api,其中检索自定义标题:X-Total-Count:“项目总数”,我使用的角度为ngResource
。使用ngResource访问标题
我厂是这样的:
app.factory("shopFactory", function ($resource) {
return {
User: $resource("http://localhost:58495/users/api/User/?id=:id", { id: "@id" }),
Category: $resource("http://localhost:58495/category/:id", { id: "@id" }),
Product: $resource("http://localhost:58495/products/?from=:from&to=:to", { from: "@from", to: "@to" })
};
});
当我把它叫做:
var productServer = shopFactory.Product.query({ from: 0, to: 10 }).$promise.then(function (response) {
$scope.product = response;
console.log(response);
}, function (error) {
console.log("ERROR");
console.log(error);
});
我怎样才能通过ngResource访问我的自定义标题,我可以,但用$访问HTTP,我想用$ resource的方式做,谢谢
谢谢,它的工作完美无缺。我只有一个问题,使用$ promise.then和成功函数有什么区别,非常感谢。 –