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. But what should I do to show, when there are no matches, on that same popup "No matches found"?
当我键入它时,它会显示typeahead-popup div中的选项。但是,如果没有匹配,我应该怎么做才能在同一个弹出窗口中显示“找不到匹配项”?
Thanks in advance
提前致谢
2 个解决方案
#1
4
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. That way the user can't choose "no results".
如果没有结果,则返回一个元素,表示没有结果。在ng-template中你可以输入一个ng-if来检查它是否是无结果元素,并使其不可点击。这样用户就无法选择“无结果”。
#2
1
The UI Bootstrap website shows a directive typeahead-no-results="noResults"
. Then it has <div ng-show="noResults">
with a glyphicon and the message "No Results Found". The full code is:
UI Bootstrap网站显示了一个指令typeahead-no-results =“noResults”。然后它有
<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>
#1
4
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. That way the user can't choose "no results".
如果没有结果,则返回一个元素,表示没有结果。在ng-template中你可以输入一个ng-if来检查它是否是无结果元素,并使其不可点击。这样用户就无法选择“无结果”。
#2
1
The UI Bootstrap website shows a directive typeahead-no-results="noResults"
. Then it has <div ng-show="noResults">
with a glyphicon and the message "No Results Found". The full code is:
UI Bootstrap网站显示了一个指令typeahead-no-results =“noResults”。然后它有
<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>