Search code examples
angularjsmongodbgetangular-filters

why does my angularjs $http.get request with params not return filtered results?


I apologise if this is a stupid question. I am running a $http.get() request in my client controller to retrieve objects including a particular id. If anyone can point me in the right direction I would be very grateful. Thanks in advance!

$http
    .get('api/offers', {
        params: {
            taskId: vm.task._id
        }
     })
     .success(function (data,status) {
          vm.task.offers = data;
          console.log(data);
//          if (vm.task.offers.taskId === vm.task._id) {
//              console.log(vm.task.offers);
//          }
     });

However, the request is returning all data in the mongodb document.

I have tried filtering in my html page but also not working.

<ul class="list-group" ng-repeat="offer in vm.task.offers | filter: { offer.taskId : vm.task._id } : true">

Get request is getting /api/offers?taskId=570999f043131bb7ade86185 in my browser network resources, again this end point returns all entries in my document, rater than filtered by the taskId.


Solution

  • On ng-repeat filtering you made a mistake, have it like below.

    ng-repeat="offer in vm.task.offers | filter: { taskId : vm.task._id } : true"