Я использую WebAPI на стороне сервера:
public int Get(int productId)
{
//removed the actual logic to simplify the example
return 101;
}
Угловой:
$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 } });
}])
Вместо числа 101 я вижу обещание: {"0":"1","1":"0","2":"1"}
Как я могу реализовать обратный вызов, чтобы увидеть объект, а не обещание?
then
, например$scope.averageQuantity = Quantity.query(queryArgs).then(function(results){ /* console.log(results.data */ })
- person Marc Kline   schedule 20.05.2014$scope.averageQuantity = Quantity.query(queryArgs, {}, function(returnValue, responseHeaders) { console.log(returnValue); });
- person Toonsylvania   schedule 20.05.2014then
не зависит от jQuery. Angular включает в себя $q, созданный по образцу Q для промисов, который включает методthen
. Тем не менее, я должен признать, что я был неправ в своем первоначальном суждении. Проблема не имеет ничего общего с обратными вызовами или обещаниями. Мой предстоящий ответ покажет, в чем проблема. - person Marc Kline   schedule 20.05.2014