I have written a filter function which will return data based on the argument you are passing. I want the same functionality in my controller. Is it possible to reuse the filter function in a controller?
This is what I’ve tried so far:
function myCtrl($scope,filter1)
{
// i simply used the filter function name, it is not working.
}
Inject $filter to your controller
Then wherever you want to use that filter, just use it like this:
If you want to pass arguments to that filter, do it using separate parentheses:
Where
arg1is the array you want to filter on andarg2is the object used to filter.