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.
Answer: A is the correct option. The syntax of applying multiple filters in AngularJS can be written as: {{ expression | filter1 | filter2 | ... }}
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.
Filters can be added to expressions by using the pipe character | , followed by a filter.
The pipe symbol ( | ) is used to chain multiple filters together.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With