【问题标题】:Angular UI bootstrap typeahead select when there is only one match当只有一个匹配项时,Angular UI bootstrap typeahead select
【发布时间】:2016-06-19 18:55:57
【问题描述】:

是否可以配置(内置或通过自定义指令)Angular UI bootstrap typeahead,以便在只有一个匹配项时选择值?有 typeahead-select-on-exact 选项,但要使其正常工作,输入的值必须与 typeahead 的完整选项匹配

请参阅下面的 plunker。我添加了typeahead-select-on-exact,所以当你输入“葡萄牙”时,它会选择值。 我想要实现的行为是当您键入“Portu”时,预输入也会选择葡萄牙(因为这是唯一可能的匹配项)。

 <input type="text" typeahead-select-on-exact="true">

http://plnkr.co/edit/ddAsXQuXjOf7rKkKmYuz?p=preview

【问题讨论】:

    标签: angular-ui-bootstrap angular-ui angular-ui-typeahead


    【解决方案1】:

    对于我的用例,我最终将以下内容添加到 getLocation() 方法中(请参阅问题中的 plunker 示例)

    if(response.data.length === 1) {
       $scope.asyncSelected = response.data[0].name
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-05-30
      相关资源
      最近更新 更多