我研究并浏览了其他解决方案,但我似乎无法让它继续工作。
我的主要问题是 uib-typeahead 似乎根本不起作用,无论是指向返回值还是指向函数(我将在下面提供示例)。
为此,我正在使用/继承 Angular.UI.Bootstrap (v2.5.0)。
我的 HTML 调用(尝试使用异步和不使用异步)是:
<input type="text" ng-model="selected" uib-typeahead="r.ResourceValueId as r.Value for r in ResourceValues | filter:$viewValue" class="form-control">
<input type="text" ng-model="asyncSelected" placeholder="Resources" uib-typeahead="item.ResourceValueId as item.Value for item in getResourceValuesSearch($viewValue)"
typeahead-loading="loadingResources" typeahead-no-results="noResults" class="form-control">
<i ng-show="loadingResources" class="glyphicon glyphicon-refresh"></i>
<div ng-show="noResults">
<i class="glyphicon glyphicon-remove"></i> No Results Found</div>
两个输入都没有出现下拉菜单,并且已填充 ResourceValues(使用正常的“选择”进行测试)。对于异步,它根本不调用 getResourceValuesSearch() 函数。
更新:我同时包含 ngSanitize 和 ngAnimate 并在模块上运行。所以这个问题似乎与 angular-ui-typeahead 直接相关,因为其他一切似乎都工作得很好。
最佳答案
编写一个调用 Api 的服务并从中获取 promise 。在您的函数中使用服务并返回数据。
关于javascript - Angular uib-typeahead 无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43621602/