I am using WebAPI on the server side:
public int Get(int productId)
{
//removed the actual logic to simplify the example
return 101;
}
The Angular:
$scope.showDetails = function (product) {
$scope.selectedProduct = product;
var queryArgs = { productId: product.id };
$scope.averageQuantity = Quantity.query(queryArgs, function() {
//callback function
console.log($scope.averageQuantity); // this shows a promise instead of an actual object
//and then open modal and pass the $scope as a parameter
});
};
//the resource:
.factory('Quantity', ['$resource', function ($resource) {
return $resource('/api/quantity', {}, { 'query': { method: 'GET', isArray: false } });
}])
Instead of the number 101 I see the promise: {"0":"1","1":"0","2":"1"}
How can I implement the callback in order to see the object and not the promise?
then, such as$scope.averageQuantity = Quantity.query(queryArgs).then(function(results){ /* console.log(results.data */ })$scope.averageQuantity = Quantity.query(queryArgs, {}, function(returnValue, responseHeaders) { console.log(returnValue); });thenisn't jQuery specific. Angular includes $q, patterned after Q for promises, which includes athenmethod. Still, I must admit that I was wrong in my initial judgement. The problem has nothing to do with callbacks or promises. My upcoming answer will show what the problem is.