简体   繁体   中英

How to use filter in controller in angularjs

I have given code in my function.

 $scope.FilteredList = $filter('filter')(ProductService.Products, $scope.FilterExpr, false);

where $scope.FilterExpr is bind with text field.

Above filter works as expected for me, and when user types something in text field, $scope.FilteredList gets populated with filtered items.

ProductService.Products is an array of objects with following fields in object. name , mrp , sp , incart .

I want to create another filter which filters all the items where incart value is > 0.

what should i use instead of ????? in below line.

  $scope.FilteredList = $filter('filter')(ProductService.Products, ?????, false);

You don't need to use $filter again. Do use .filter over $scope.FilteredList collection to get desired result.

var result = $scope.FilteredList.filter(function(item){
   return item.incart > 0;
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM