使用 angular.js ui 和 bootstrap typeahead 进行异步调用以检索自动搜索建议

using angular.js ui and bootstrap typeahead for asynchronous call to retrieve auto suggestions for search

我正在使用 angular 1.3.0 和 bootstrap 3.2.0。我正在尝试从我的 mysql 数据库中异步获取数据,但我在 bootstrap typeahead 方面遇到了一些问题。

我的代码index.html:

<input type="text" ng-model='locality' name="locality" typeahead="name for locality in getLocality($viewValue) | filter:$viewValue" typeahead-loading="loadingLocations" class="form-control size1 input-medium search-query"
    placeholder="Enter Organization name/service">
</input>

main.js 用于提前输入的文件

    $scope.getLocality = function(val) {
       console.log(val);
       var url = $rootScope.baseURL + '/api/location?locality=' + val;
       console.log(url);
       return $http.get(url, {
           params: {
               name: val,
               sensor: false
           }
       }).then(function(response) {
           var addresses = [];
           angular.forEach(response.data.resulults, function(item) {
               addresses.push(item.formatted_name);
           });
           return addresses;
       });

    };

当我调试时,这个值会很好,但我没有收到任何自动建议,请任何人帮助我解决这个问题。

它工作正常谢谢你@tiblu
index.html 文件

<input type="text" ng-model='locality' name="locality"
                                typeahead="name for name in getLocality($viewValue)"
                                typeahead-loading="loadingLocations"
                                class="form-control size1 input-medium search-query"
                                placeholder="Enter Organization name/service">
                                </input>



    .js file    


    $scope.getLocality=function(val){
                        console.log(val);
                                    var url=$rootScope.baseURL + '/api/location?locality='+val;
                                console.log(url);
                                              return $http.get(url,{

                                                           params: {
                                                                     name: val,
                                                                     sensor: false
                                                                     }
                                                                 }).then(function(response){
                                                                    console.log(response);
                                                                    console.log(response.data); 
                                                                    var addresses=[];
                                                                           angular.forEach(response.data.data,function(item){
                                                                            addresses.push(item.name);
                                                                            //return item.formatted_name;
                                                                            console.log(response.data);
                                                                           });
                                                                          return addresses;
                                                                         /*return response.data.results.map(function(item){
                                                                           return item.formatted_address;*/
                                                                  });

                    };