サーバー側で 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"} という約束が表示されます。
プロミスではなくオブジェクトを表示するためにコールバックを実装するにはどうすればよいですか?