angularjs – 如何获取在ui-select搜索框中输入的值?

前端之家收集整理的这篇文章主要介绍了angularjs – 如何获取在ui-select搜索框中输入的值?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在使用ui-select( https://github.com/angular-ui/ui-select).

ui-select支持我们搜索,选择和多选.但是,如何在ui-select搜索框中输入用户输入的值?如果用户键入的值不正确,我想显示错误消息.

示例:在下面这个带有Select2主题的plunker中,当用户输入:’asdasd'(此文本与任何结果不匹配)时,我想显示一条消息“找不到任何结果!”通过分配’scope.person.selected’

plnkr.co/edit/a3KlK8dKH3wwiiksDSn2?p=preview

我怎样才能做到这一点?

非常感谢!

解决方法

angular_ui_select中的输入数据进入$select.search模型.
您可以使用ui-select-choice的refresh属性.
只需在refresh =“test($select.search)”中传递函数,并分别使用refresh-delay和minimum-input-length属性设置延迟和最小输入长度.
这是一个简单的例子:

<ui-select ng-model="model" theme="theme">
     <ui-select-match>{{data}}</ui-select-match>
     <ui-select-choices repeat="options in data" refresh="yourFunction($select.search)" refresh-delay="100" minimum-input-length="1"></ui-select-choices>      
</ui-select>

我建议你仔细阅读文档,希望它会有所帮助.
angular-ui-select

猜你在找的Angularjs相关文章