RONE
RONE

Reputation: 5485

Search Filter using angular, How to use '| filter: 'some text' from controller

What is wrong in this:

jsfiddle.net/TTY4L/3/

I am trying to make a filter kind of list, when i enter some value, say 'avi', it should list like

I know the logic to do So, {{['Avi','Ravi','Raj','Raghuram'] | filter:'avi'}}, But i could not able to get, how to put this in controller, and display from there, Can i use $filter for this, If yes, then how can i.

Upvotes: 0

Views: 95

Answers (3)

Jayram
Jayram

Reputation: 19588

You can inject the filter into the controller like this.

function MyCtrl($scope, $filter){

     $scope.names = $filter('filter')('searchText');
}

Upvotes: 0

nilsK
nilsK

Reputation: 4351

try this:

<li ng-repeat="searchItem in searchItems | filter:searchFilter">{{searchItem}}</li>

abd here the fiddle

Upvotes: 1

BKM
BKM

Reputation: 7079

You could do something like this in your ng-repeat

<li ng-repeat="searchItem in searchItems|filter:searchFilter:strict">{{searchItem}}</li>

Upvotes: 0

Related Questions