mdv
mdv

Reputation: 945

How to use Angular Query resource

I'm using MEAN.JS 0.4 and I need some help with Angular Resource.

My problem is this:

I want to make this API and be able to filter data server side, but I dont know how to use this Query method.

I want to do something like this:

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

This is my actual Angular service:

//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'
      }
    });
  }
]);

Upvotes: 0

Views: 48

Answers (1)

Sim
Sim

Reputation: 385

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

or

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

Upvotes: 1

Related Questions