2015-09-04 73 views
1

嗨我在我的angularjs站点使用bootstrap ui typeahead。这很好。只是想知道当用户输入不在列表中的东西时,是否可以显示一些文本,例如“找不到匹配项”。Angular-bootstratp ui typeahead没有匹配的结果

+1

第二[示例](https://angular-ui.github.io/bootstrap/#/typeahead)显示下面的一个消息当没有匹配时输入。那是你在找什么? – muenchdo

回答

6

typeahead指令包含此属性,typeahead-no-results。

下面是一个例子:

<input type="text" ng-model="asyncSelected" placeholder="Placeholder Text" typeahead="address for address in getLocation($viewValue)" typeahead-no-results="noResults" class="form-control"> 

然后使用纳克 - 如果或NG-显示以显示错误消息。

<div ng-if="noResults"> 
    No Results Found! 
</div> 

更多的阅读材料一定要检查出bootstrap-ui docs

+1

你是对的。我已经相应地更新了答案。 – MLBCodes

+2

这可能不言而喻,但如果页面上有两个或更多的Typeahead,则设置typeahead-no-results =“noResults”将导致它们全部显示。因此,如果您希望它们独立运行,请设置typeahead-no-results =“noResultsA”,typeahead-no-results =“noResultsB”等。 – MaxRocket