2015-09-04 69 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