我有一個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和成功函數有什麼區別,非常感謝。 –