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

空扰寡人 提交于 2020-01-11 04:56:06

问题


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"}];

回答1:


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

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



回答2:


As suggested by @Daiwei, 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!



来源:https://stackoverflow.com/questions/21012036/how-to-start-filtering-only-when-the-length-of-querytext-is-equal-to-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!