在下拉列表中,各個下拉選項(xiàng)一開始不現(xiàn)實(shí),輸入關(guān)鍵字后顯示相關(guān)下拉選項(xiàng),比如輸入a就出現(xiàn)app apple,可是當(dāng)清空輸入框的字符后,下拉選項(xiàng)就全部顯示出來了,請問這是為什么?后面我將 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>
angular1.x實(shí)現(xiàn)下拉提示中的問題
胡說叔叔
2018-10-17 13:35:16