我以 fork 了一个 Plunker 为例 http://plnkr.co/edit/ylR1mel46FXTXzdvfHpa?p=preview
当在标记中使用内联 promise 时,如下所示:
<div class='container-fluid' ng-controller="TypeaheadCtrl">
<pre>Model: {{selected| json}}</pre>
<input type="text" ng-model="selected" typeahead="state for state in getStates($viewValue) | limitTo: 5">
</div>
如果您在 Controller 中输入“A”,您可以看到 limitTo 选项被忽略。可以这样使用吗?
最佳答案
您需要限制您的 promise 回调中的结果。 <强> https://github.com/angular-ui/bootstrap/issues/1740
AngularJS filters are executing synchronously and if you write your expression like address for address in getLocation($viewValue) | filter:$viewValue this part getLocation($viewValue) means that a filter would filter a promise object (which is noop as filter filter can only operate on arrays). The correct approach here is to do filtering on the server-side (this is the whole point of having async results from the server). If you still want to do further filtering on the client side you can do so in the promise callback function, in JavaScript.
关于javascript - 使用 Promises 时,Angular UI Typeahead 限制结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39351528/