How do you filter ng-repeat with a multi-keyword query in AngularJS?  

  RSS

TopicCreator
(@topiccreator)
Eminent Member Moderator
Joined: 12 months ago
Posts: 12
04/07/2018 5:05 pm  

How do you filter ng-repeat with a multi-keyword query in AngularJS?


ReplyQuote
TechGroup Admin
(@admin)
Eminent Member Admin
Joined: 1 year ago
Posts: 11
04/07/2018 5:18 pm  

To filter an ng-repeat for multiple key words, you'll need to write a custom filter. You can define a custom filter the same way you define a controller: 

  1. var app = angular.module('myApp', []);
  2. //The filter will at least have one input argument, I called it input.
  3. //This is the data we are filtering
  4. app.filter('myFilter', function(input) {
  5. //check to see if the data is one of the two things I'm looking for
  6. if(input == a || input == b) {
  7. return input;
  8. }
  9. });

On the view side, you can use your custom filter like so: 

  1. class="someDiv" ng-repeat="item in itemList | myFilter">


ReplyQuote
Share:
  
Working

Please Login or Register