Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass multiple parameter in angular filter function, not custom filter

I tried hard and visit lot of similar question like this but still unable to solve this issue.

I want to pass extra parameter in angular filter function. I found solution as below but it's not working. I am getting undefined for object which I have used in ng-repeat.

<li ng-repeat="user in users | filter:isStatus(user,secondParam)">{{user.name}}</li>

There are solution for angular custom filter as below but that also not working with angular filter function.

<li ng-repeat="user in users | filter:isStatus:user:secondParam">{{user.name}}</li>

jsFiddle - You can see my problem here.

like image 509
Jay Shukla Avatar asked Dec 16 '14 14:12

Jay Shukla


People also ask

What is correct way to apply multiple filters in angular?

Answer: A is the correct option. The syntax of applying multiple filters in AngularJS can be written as: {{ expression | filter1 | filter2 | ... }}

How do you indicate a parameter to a filter in AngularJS?

This is called "chaining" and uses the following syntax: {{ expression | filter1 | filter2 | ... }} E.g. the markup {{ 1234 | number:2 }} formats the number 1234 with 2 decimal points using the number filter.

What is the correct way to apply filter in angular?

Filters can be added to expressions by using the pipe character | , followed by a filter.

Which character is used to chain multiple filters in AngularJS?

The pipe symbol ( | ) is used to chain multiple filters together.


1 Answers

According to your case, you can use predicate expression instead of custom filter:

<li ng-repeat="user in users | filter:{status: status, name: name}">{{user.name}}</li>

Take a look at this fiddle: http://jsfiddle.net/ovym2tpr/28/

You can use custom filter in anyway, it just performs not very well especially under nested ng-repeat

like image 121
shawnzhu Avatar answered Sep 22 '22 03:09

shawnzhu