Asynchronous Angularjs引导UI typeahead不异步工作

Asynchronous Angularjs引导UI typeahead不异步工作,asynchronous,angular-ui,typeahead,angular-http,Asynchronous,Angular Ui,Typeahead,Angular Http,我正在异步使用angular bootstrap ui typeahead返回一个记录数组,但无法让它工作。通过下载页面加载上的所有数据,我已经让typeahead在同步执行操作时工作。两种情况下的数据看起来都一样;异步版本似乎失败了,因为typeahead只得到承诺,而不是返回的数据 angularjs控制器如下所示: 同步的 vm.doctorList=[] vm.doctorList=[]; 函数getAllDoctors(){ agreementService.getAllDoctor

我正在异步使用angular bootstrap ui typeahead返回一个记录数组,但无法让它工作。通过下载页面加载上的所有数据,我已经让typeahead在同步执行操作时工作。两种情况下的数据看起来都一样;异步版本似乎失败了,因为typeahead只得到承诺,而不是返回的数据

angularjs控制器如下所示:

同步的 vm.doctorList=[]

vm.doctorList=[];
函数getAllDoctors(){
agreementService.getAllDoctors()
.然后(功能(响应){
vm.doctorList=response.data;
});

}
对于异步,您需要返回承诺对象。假设您的
agreementService
返回
$http
请求/承诺(看起来是这样),您的搜索函数应该如下所示:

vm.getExistingDoctor = function (value) {
      return agreementService.getExistingDoctor(value).then(function (response) {
          return response.data;
      });
}
注意,我删除了对值长度的检查,因为uibTypeahead指令已经阻止它在不满足最小长度时异步调用数据。我还建议使用ng选项来定义去盎司值,这样您就不会在每次击键时调用API<代码>ng选项={debounce:500}