Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to start filtering only when the length of querytext is equal to 2

How can I be able to start filtering only when the querytext's length is equal to 2?

I have this code and I do not 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"}];
like image 835
user2756589 Avatar asked Jan 09 '14 05:01

user2756589


1 Answers

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

<input type="search" ng-model="querytext" ng-minlength="2" />
<!--                                      ^^^^^^^^^^^^^^^^ -->
like image 154
Daiwei Avatar answered Oct 11 '22 18:10

Daiwei