Jak mogę uzyskać dostęp do kodu stanu odpowiedzi HTTP po pomyślnym żądaniu za pomocą Restangular?
Przykład CoffeeScript
Restangular.all("orders").getList().then (result) ->
console.log result # no status code
console.log "Preferably, status code should be here: ", result.status
, (error) ->
console.log "Error status code: ", error.status # this works
Próbowałem zaimplementować ekstraktor odpowiedzi, aby dołączyć go jako metadane, ale kod stanu jest już usuwany do czasu, gdy wpływa do ekstraktora.
Odpowiedzi:
14 dla odpowiedzi № 1Można użyć setFullResponse w konfiguracji modułów, aby pobrać kod stanu na żądanie zakończone powodzeniem.
https://github.com/mgonto/restangular#setfullresponse
var app = angular.module("app", ["restangular"]);
// Change setFullResponse to be true in the modules config.
app.config(["RestangularProvider", function (RestangularProvider) {
RestangularProvider.setFullResponse(true);
}]);
// Using the new response format.
app.controller("someController", ["Restangular", function (Restangular) {
Restangular.all("orders").getList().then(function (result) {
// Response from the server.
console.log(result.data);
// Response status code.
console.log(result.status);
});
}]);
Kawa opisana:
app = angular.module("app", ["restangular"])
// Change setFullResponse to be true in the modules config.
app.config ["RestangularProvider", (RestangularProvider) ->
RestangularProvider.setFullResponse true
]
// Using the new response format.
app.controller "someController", ["Restangular", (Restangular) ->
Restangular.all("orders").getList().then (result) ->
// Response from the server.
console.log result.data
// Response status code.
console.log result.status
]
Mam nadzieję że to pomoże!