正如HarishR在评论中提到的那样,尚无对此功能的内置支持。
但是我只想尝试一下,结果是这样:http :
//plnkr.co/edit/Qrnat8yTvISuM1qHHDlA?p=preview
它包含许多使它起作用的技巧:
- 为了使用.trigger()包含jQuery,可以用本机JS替换,但我很懒。
- 使用ng-focus调用.trigger(’input’)触发字体弹出
- 使用ng-trim =“ false”禁用输入的值自动修整
- 一个自定义的empty-typeahead指令,可与ngModel的控制器进行交互,以应用secretEmptyKey逻辑来绕过typeahead-min-length检查:
.directive('emptyTypeahead', function () { return { require: 'ngModel', link: function (scope, element, attrs, modelCtrl) { // this parser run before typeahead's parser modelCtrl.$parsers.unshift(function (inputValue) { var value = (inputValue ? inputValue : secretEmptyKey); // replace empty string with secretEmptyKey to bypass typeahead-min-length check modelCtrl.$viewValue = value; // this $viewValue must match the inputValue pass to typehead directive return value; }); // this parser run after typeahead's parser modelCtrl.$parsers.push(function (inputValue) { return inputValue === secretEmptyKey ? '' : inputValue; // set the secretEmptyKey back to empty string }); } } })一个自定义过滤器比较器函数,当一个参数为secretEmptyKey时始终返回true(显示所有结果):
$scope.stateComparator = function (state, viewValue) {return viewValue === secretEmptyKey || (‘’+state).toLowerCase().indexOf((‘’+viewValue).toLowerCase()) > -1;
};删除limitTo过滤器以显示所有结果
如果内容太长,则设置max-height和溢出CSS属性以显示滚动条
做完了!



