我在服务器端使用 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"}
如何实现回调以查看对象而不是承诺?