Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AngularJS filter array

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>
like image 725
vzhen Avatar asked Apr 02 '13 05:04

vzhen


People also ask

What is filter array in angular?

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.

What is AngularJS filter?

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.

What does filter function do in angular?

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.

What is the correct way to apply multiple filter in AngularJS?

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.


2 Answers

<li ng-repeat="foo in foos | filter:{name:'b'}">{{foo.name}}</li>
like image 141
Stewie Avatar answered Sep 23 '22 22:09

Stewie


<li ng-repeat="foo in foos | filter:'b'">{{foo.name}}</li>

might work as well

like image 34
Aladdin Mhemed Avatar answered Sep 24 '22 22:09

Aladdin Mhemed