如果输入的过滤器只有大于3(或N)个字符时才能获得ng-repeat的结果?
我尝试了以下内容(过滤器:input.lenght> 3 ):
<input type="text" ng-model="input" placeholder="Search">
<li ng-repeat="detail in details | filter: input.lenght > 3">
{{ detail.name }}
</li>
但它不起作用。我怎么能做我想做的事?问候朋友。
解决方案:
<input type="text" ng-model="input" ng-minlength="3" placeholder="Search">
答案 0 :(得分:3)
对此过滤器使用三元运算
<li ng-repeat="detail in details | filter: (input.length > 3)? input : ''">
angular.module("app",[])
.controller("ctrl",function($scope){
$scope.details = [{"name":"ssss"},{"name":"aaaa"},{"name":"cccc"}]
})
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="app" ng-controller="ctrl">
<input type="text" ng-model="input" placeholder="Search">
<li ng-repeat="detail in details | filter: (input.length > 3)? input : ''">
{{ detail.name }}
</li>
</div>