UI-bootstrap typeahead无法解决诺言 [英] UI-bootstrap typeahead does not resolve promise
问题描述
我对UI-Bootstrap的预输入有疑问,主页上有一个标准示例演示了预输入用法:
Hi, I have a problem with UI-Bootstrap's typeahead, there is standard example on the homepage that demonstrates typeahead usage:
http://plnkr.co/edit/LS5OMsnQtdsJ87eW4pjG?p=preview
在我开始使用带有typeahead
指令的promises之前,这个示例可以很好地工作:
http://plnkr.co/edit/ZuUBDOPcOJIW0Bkskrb5?p=preview
This example works pretty fine until I start using promises with typeahead
directive:
http://plnkr.co/edit/ZuUBDOPcOJIW0Bkskrb5?p=preview
更改非常简单,我使用$ timeout服务将直接变量初始化替换为延迟初始化,结果提前输入停止工作
The change is pretty simple, I've replaced direct variable initialisation with delayed initialisation using $timeout service, as a result typeahead stops working
我做错了什么?明确指出了UI-Bootstrap的预输入:works with promises and it means that you can retrieve matches using the $http service with minimal effort
What am I doing wrong? It is clearly stated that UI-Bootstrap's typeahead: works with promises and it means that you can retrieve matches using the $http service with minimal effort
谢谢
推荐答案
您应该返回一个承诺,以解决匹配的结果:
You should be returning a promise that resolves to matched results:
$scope.getStates = function($viewValue) {
return $timeout(function () {
return filterFilter(['Alabama', 'Alaska', ...], $viewValue);
}, 1000);
};
,然后使用HTML:
<input type="text" ng-model="selected" typeahead="state for state in getStates($viewValue)">
这是一个工作正常的小伙伴: http://plnkr.co/edit/RAkzX0UoWHVLUOZ6jEyA?p=预览
Here is a working plunk: http://plnkr.co/edit/RAkzX0UoWHVLUOZ6jEyA?p=preview
您写出的诺言被过滤的方式.
The way you've written your expression in a promise being filtered.
这篇关于UI-bootstrap typeahead无法解决诺言的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!