5

I have input field:

<input type="text" ng-model="in">

Also select list:

<select ng-model="sel"></select>

How I can use two filters in ng-repeat something like:

ng-repeat="item in arr | filter:sel | filter:in"

My select list in header:

<div ng-controller="TestController">
   <select ng-controller="in"></select>
</div>

Also in bottom of page I have:

<div ng-controller="TestController">{{in}}</div>

But {{in}} is empty

5
  • You're using correct. Can you share your code where you're getting error. Commented Jul 11, 2015 at 19:43
  • Do you have value property of <option> tag set for each select <option>? Commented Jul 11, 2015 at 19:46
  • @ Kaffarov, did you check my answer below? Commented Jul 11, 2015 at 20:05
  • This doesn't make any sense; <select ng-controller="in"> isn't even valid. also, why are you repeating ng-controller in another div? That div won't have access to the $scope of the other controller.... Commented Jul 11, 2015 at 20:52
  • it would be much easier to see what is going on if you post all the relevant code from the page, and even better, if you create a plunker demonstrating your issue. plnkr.co Commented Jul 11, 2015 at 20:55

1 Answer 1

7

You're doing right. The following can be taken as an example to apply filter. You can modify it to apply multiple filters as well.

Search field

<input type="text" ng-model="in" placeholder="Enter value to search.">
<select ng-model="sel">
<option value="1">One</option>
<option value="2">Two</option>
</select>

Using filter in ng-repeat:

<div>    
<tr ng-repeat="item in filteredData = (arr | filter:in | filter: sel)">
</div>

or simple way for multiple filters like as per your question

<tr ng-repeat="item in arr| filter:in | filter: sel">

Then showing message whether data found or not.

<div ng-show="!(filteredData ).length">
    No matching data found
</div>
Sign up to request clarification or add additional context in comments.

2 Comments

It does not work for me. because I have two same controllers in HTML page. Updated question
what you mean by " I have two same controllers in HTML page"? it looks weired statement. Can you post your whole code?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.