I have been stuck on this for quite a while now and cannot figure out why the value is not being returned. I am using Angular $resource
to make a GET request to an API.
My $resource factory looks like this:
.factory("Bookings", function ($resource) {
return $resource("www.example/bookings_on_date/:day", {});
})
I have tried to implement promises but am unable to do so correctly.
function getBookings(day){
return Bookings.get({"day": day}).$promise.then(function(data) {
console.log(data.total)
return data.total;
});
}
$scope.todaysBookings = getBookings(TODAY);
$scope.tomorrowsBookings = getBookings(TOMORROW);
When I view either console.log($scope.todaysBookings)
or $scope.tomorrowBookings
in the console it returns undefined.
I have also tried everything from this jsfiddle but unfortunately have not had any luck.