0

Does angular have a onfilter method or onquery as you type to query through results:

for example:

<input type='text' ng-model='query'>
<table>
    <tr>
        <td>Name</td>
        <td># of Enrollments</td>
    </tr>
    <tr ng-repeat='c in courses | filter:query' onfilter='someStuff()'>
        <td>{{c.name}}</td>
        <td>{{c.enrollmentLength}}</td>
    </tr>
</table>

when I type in the input text the letter "a", I want it to call the someStuff() function.

1
  • 2
    Why not just do <input type='text' ng-model='query' ng-change="someStuff()">? Commented Jul 22, 2014 at 16:56

2 Answers 2

4

The way you do this is with a watch inside your controller:

$scope.$watch('query', function(newval) {
   // this will fire when query is changed
});
Sign up to request clarification or add additional context in comments.

Comments

1

Filter can call a function instead of using an expression. Here's an example:

$scope.processQuery = function(course) {
  // do some processing
};


<input type='text' ng-model='query'>
<table>
    <tr>
        <td>Name</td>
        <td># of Enrollments</td>
    </tr>
    <tr ng-repeat='c in courses | filter:processQuery'>
        <td>{{c.name}}</td>
        <td>{{c.enrollmentLength}}</td>
    </tr>
</table>

Comments

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.