繁体   English   中英

AngularJS UI-Bootstrap Typeahead没有匹配项

[英]AngularJS UI-Bootstrap Typeahead no matches

我一直在寻找,但没有发现与此有关的问题。

我正在使用Angular UI-bootstrap typeahead。

所以我有

<input type="text" ng-model="loc" typeahead="location for location in filteredLocations = (locations | filter:$viewValue)" class="form-control" placeholder="Location" />

当我键入它时会显示typeahead-popup div中的选项。 但是,如果没有匹配,我应该怎么做才能在同一个弹出窗口中显示“找不到匹配项”?

提前致谢

您可以做的是创建自己的结果列表。 使用typeahead-template-url="customTemplate.html"并且这很容易:

<script type="text/ng-template" id="customTemplate.html">
  <a>
      <img ng-src="http://upload.wikimedia.org/wikipedia/commons/thumb/{{match.model.flag}}" width="16">
      <span bind-html-unsafe="match.label | typeaheadHighlight:query"></span>
  </a>
</script>

如果没有结果,则返回一个表示没有结果的元素。 在ng-template中你可以输入一个ng-if来检查它是否是无结果元素并使其不可点击。 这样用户就无法选择“无结果”。

UI Bootstrap网站显示了一个指令typeahead-no-results="noResults" 然后它有<div ng-show="noResults">带有一个glyphicon和消息“No Results Found”。 完整的代码是:

<h4>Asynchronous results</h4>
<pre>Model: {{asyncSelected | json}}</pre>
<input type="text" ng-model="asyncSelected" placeholder="Locations loaded via $http" uib-typeahead="address for address in getLocation($viewValue)" typeahead-loading="loadingLocations" typeahead-no-results="noResults" class="form-control">
<i ng-show="loadingLocations" class="glyphicon glyphicon-refresh"></i>
<div ng-show="noResults">
  <i class="glyphicon glyphicon-remove"></i> No Results Found
</div>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM