简体   繁体   English

AngularJS UI-Bootstrap Typeahead没有匹配项

[英]AngularJS UI-Bootstrap Typeahead no matches

I've been searching around so but found no question relating to this. 我一直在寻找,但没有发现与此有关的问题。

I am using Angular UI-bootstrap typeahead. 我正在使用Angular UI-bootstrap typeahead。

So I have 所以我有

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

When I type it shows the options in the typeahead-popup div. 当我键入它时会显示typeahead-popup div中的选项。 But what should I do to show, when there are no matches, on that same popup "No matches found"? 但是,如果没有匹配,我应该怎么做才能在同一个弹出窗口中显示“找不到匹配项”?

Thanks in advance 提前致谢

What you can do is create your own results listing. 您可以做的是创建自己的结果列表。 That's easy using typeahead-template-url="customTemplate.html" and this: 使用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>

If there are no results, return one element indicating there's no result. 如果没有结果,则返回一个表示没有结果的元素。 In the ng-template you can put a ng-if which checks if it's the no-results element and make it not clickable. 在ng-template中你可以输入一个ng-if来检查它是否是无结果元素并使其不可点击。 That way the user can't choose "no results". 这样用户就无法选择“无结果”。

The UI Bootstrap website shows a directive typeahead-no-results="noResults" . UI Bootstrap网站显示了一个指令typeahead-no-results="noResults" Then it has <div ng-show="noResults"> with a glyphicon and the message "No Results Found". 然后它有<div ng-show="noResults">带有一个glyphicon和消息“No Results Found”。 The full code is: 完整的代码是:

<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