且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

UI-bootstrap typeahead 不能解决承诺

更新时间:2023-12-04 15:03:34

你应该返回一个解析为匹配结果的 promise:

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 中:

and then in HTML:

<input type="text" ng-model="selected" typeahead="state for state in getStates($viewValue)">

这是一个有效的 plunk:http://plnkr.co/edit/RAkzX0UoWHVLUOZ6jEyA?p=预览

Here is a working plunk: http://plnkr.co/edit/RAkzX0UoWHVLUOZ6jEyA?p=preview

您在过滤的 Promise 中编写表达式的方式.

The way you've written your expression in a promise being filtered.