How to start filtering only when the length of the query text is 2

How can I start filtering only when the request length is 2?

I have this code and I don't know how to start filtering only when querytext.length> = 2

<input type="search" ng-model="querytext"> <ul> <li ng-repeat="value in filteredList | filter:querytext>{{value.Name}}</li> </ul> $scope.filteredList =[{Id:1,Name:"Soul"},{Id:2,Name:"Croft"}]; 
+7
angularjs angularjs-filter
source share
2 answers

Add the element ng-minlength="2" to the <input> .

 <input type="search" ng-model="querytext" ng-minlength="2" /> <!-- ^^^^^^^^^^^^^^^^ --> 
+27
source share

As @Daiwei suggested, here is what I did:

 <input type="search" ng-model="querytext" ng-minlength="2"> <ul> <li ng-repeat="value in filteredList | filter:querytext>{{value.Name}}</li> </ul> 

and it works! Thanks!

0
source share

All Articles