Angular 1.3 filter list of objects with array attribute

Hope someone can help me. For my current project in angular 1.3, I use this list:

$scope.myList = [{ id: "obj1", content: [{ id: 1, name: 'attr 1' }, { id: 2, name: 'attr 2' }, { id: 3, name: 'attr 3' }] }, { id: "obj2", content: [{ id: 4, name: 'attr 4' }, { id: 5, name: 'attr 5' }, { id: 6, name: 'attr 6' }] }, { id: "obj3", content: [{ id: 7, name: 'attr 7' }, { id: 8, name: 'attr 8' }, { id: 9, name: 'attr 9' }] }]; 

I would like to get an object that has the identifier X in the content array.

I used this ng-repeat:

 <ul> <li ng-repeat="item in myList | filter: {content: [{id:1}]}"> {{item}} </li> </ul> 

When I use id: 1, id: 4 or id: 7, it works, but not for other identifiers ...

Does anyone have any ideas?

Edit

I finally figured out what caused the problem, I used angular 1.3.0. After upgrading to 1.3.11, it works!

+2
arrays angularjs filter nested
Jan 26 '15 at 22:27
source share
1 answer

You can filter based on nested properties as follows:

 <li ng-repeat="item in myList | filter: {content: {id: '1'}}"> {{item}} </li> 

It is important to note that the “object” (which has the identifier X) that you receive will be at the item level.

+4
Jan 26 '15 at 22:38
source share



All Articles