在下拉列表中,各个下拉选项一开始不现实,输入关键字后显示相关下拉选项,比如输入a就出现app apple,可是当清空输入框的字符后,下拉选项就全部显示出来了,请问这是为什么?后面我将 ng-show 的判断条件改成ng-show="v.indexOf(str)!==-1 && str.length !== 0"就可以了。请问ng-show="v.indexOf(str)!==-1这个条件不够用吗?<!DOCTYPE html><html ng-app="test"><head> <meta charset="UTF-8"> <title>Document</title> <script src="../bower_components/angular/angular.min.js"></script> <script> var app = angular.module('test', []); app.controller('ctr1',function($scope) { $scope.arr = ['app', 'apple', 'beer', 'now', 'new', 'zoom', 'z-index']; }); app.directive('dropdownlist', function() { return { restrict : 'E', template :'<input type="text" ng-model="str">\ <ul>\ <li ng-repeat="v in arr" ng-show="v.indexOf(str)!==-1">{{v}}</li>\ </ul>' } }) </script></head><body ng-controller="ctr1"> <dropdownlist> </dropdownlist></body></html>
添加回答
举报
0/150
提交
取消