Let say I have an array object
[{
name: 'a',
number: 1
},
{
name: 'b',
number: 2
},
{
name: 'c',
number: 3
}]
And I just want to get the name:'b' which is array[1] values. How to pass it to the filter?
<li ng-repeat="foo in foos | filter:what_to_do_here="b"><li>
The “filter” Filter in AngularJS is used to filter the array and object elements and return the filtered items. In other words, this filter selects a subset (a smaller array containing elements that meet the filter criteria) of an array from the original array.
AngularJS Filters AngularJS provides filters to transform data: currency Format a number to a currency format. date Format a date to a specified format. filter Select a subset of items from an array. json Format an object to a JSON string.
AngularJS filter Filter The filter filter allows us to filter an array, and return an array containing only the matching items. This filter can only be used for arrays.
Using filters in view templates Filters can be applied to the result of another filter. 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.
<li ng-repeat="foo in foos | filter:{name:'b'}">{{foo.name}}</li>
<li ng-repeat="foo in foos | filter:'b'">{{foo.name}}</li>
might work as well
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