Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have an array of objects with arrays of objects in it:

var content = [
  { 
    name: 'Foo',
    sub: [{ name: 'Bar' }, { name: 'Foobar' }] 
  },
  ...
]

and a template:

<input ng-model="search" />

<div ng-repeat="item in content | filter:search>
   {{item.name}}
   <div ng-repeat="key in item">
      {{key.name}}
   </div>
</div>

Now, I use the filter filter to search for string matches, but it applies only to the first ng-repeat directive. How could I include the second directive into the search filter? Thanks in advance.

share|improve this question
    
Have you considered creating your own filter? You can refer to the documentation here –  callmekatootie Apr 4 '13 at 17:09
    
thanks, that'll be more time consuming though –  Metzger Apr 5 '13 at 12:44
add comment

2 Answers

You can simply apply a second filter expression to your other ng-repeat

<div ng-repeat="key in item | filter:secondFilterExpression">

See docs here http://docs.angularjs.org/api/ng.filter:filter

share|improve this answer
    
this makes a separate filter, so that the 2 directives are oblivious to each other –  Metzger Apr 5 '13 at 10:11
add comment
up vote 0 down vote accepted

Ok, I've 'flattened' the object to a simple collection before passing it through the controller to the template, so I don't have to worry about a second ng-repeat cycle. The output is

[{ name : 'foo' }, { name : 'bar' }, { name : 'foobar' }]
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.