2015-12-10 30 views
0

我正在使用MEAN.JS 0.4,我需要一些關於Angular Resource的幫助。如何使用Angular Query資源

我的問題是這樣的:

我想使這個API,並能夠過濾數據服務器端,但我不知道如何使用這個查詢方法。

我想要做這樣的事情:

Products.query({ 
    stock: 0 
}, function(result){ 
    console.log(result) 
}); 

這是我的實際角度服務:

//Discounts service used for communicating with the discounts REST endpoints 
angular.module('discounts').factory('Discounts', ['$resource', 
    function ($resource) { 
    return $resource('api/discounts/:discountId', { 
     discountId: '@_id' 
    }, { 
     update: { 
     method: 'PUT' 
     } 
    }); 
    } 
]); 

回答

1
Discounts.query({stock: 0}).$promise 
    .then(function(data) { 
     products = data; }) 

products = Discount.query({stock: 0}, function() { 
    //do something whith products 
});