I'm facing an issue with retrieving data from a Restangular promise. Instead of receiving pure JSON data, I always end up with a promise object.
Here is the response from my API:
localhost:3000/api/meal
{
"status": "success",
"data": [
{
"meal_id": 4,
"meal_type_id": 2,
"description": "blahblah",
"price": "3.50",
"info": "120/120/20g",
"restaurant_id": 2
},
...
...
}
],
"message": "Retrieved ALL meals"
}
This is the configuration method I'm using to extract data from the response:
RestangularProvider.addResponseInterceptor(function(data, operation, what, url, response, deferred) {
var extractedData;
if (operation === 'getList') {
return data.data;
} else {
extractedData = data.data;
}
return extractedData;
});
Here is how I attempt to retrieve data from my API:
Restangular.all('meal').getList().then(function(meals) {
$scope.menu = meals;
console.log($scope.menu);
});
Unfortunately, I keep getting unexpected responses like this: https://i.sstatic.net/pvjTJ.png https://i.sstatic.net/xYSUw.png
All I need is the JSON array from the "data" field to use in my application.