I'm trying to retrieve a JSON object from my backend using Restangular.
1) This works great, but I don't know how I can handle errors because there is no callback/promise function :
meals = restAngular.all('meal').getList({date: selectedDate}).$object;
The following with the promises doesn't work :
restAngular.all('meal').getList({date: selectedDate}).then(function(newMeals){
console.log(newMeals);
meals = newMeals;
});
I got a Restangular object in my "newMeals" object instead of my Json object. Something like :
addRestangularMethod: function (){var g=arguments,h=a?u:this; all: function () { [native code] } allUrl: function () { [native code] } clone: function () { [native code] } customDELETE: function () { [native code] } etc..
How can I get my JSON "meals", using promises and being able to handle potential errors ?
2) Additional question : is Restangular still a good choice since Angularjs 1.2 and his better new $resource is implemented ?
Thanks a lot
You can do something like this:
restAngular.all('meal').getList({date: selectedDate}).then(function(newMeals){
console.log(newMeals);
meals = newMeals;
}, function(response) {
console.log("Error with status code", response.status);
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With