小编poo*_*666的帖子

Angular-UI预先输出结果未显示在下拉列表中

我正在使用Angular-ui typeahead组件来命中自动完成API,而我正在解析我回到一个名为的数组中的数据resp.但是,我没有看到数据传递到UI中的自动完成下拉列表.顺便说一句,控制器有一个console.log,可以正确显示数据,所以我知道它从api调用返回.

这是我的控制器功能:

$scope.getLocationForSearch = function(locationString){

    $scope.locationString = locationString;
    var url = '/autoComplete/' + locationString ;
    $http({
        method: 'GET',
        url: url            
    }).then(function successCallback(response) {
        console.clear();
        var resp = response.data.RESULTS.map(function(item){
            console.log(item.name);
            return item.name;
        });

        return resp;

      }, function errorCallback(response) {
        console.log(response); 
    });     
}
Run Code Online (Sandbox Code Playgroud)

在我的HTML中:

    <div class="input-group">
        <input 
            type="text" class="form-control" ng-model="asyncSelected" placeholder="Search city or zip code"
            uib-typeahead="item for item in getLocationForSearch($viewValue)"/>
        <i ng-show="loadingLocations" class="glyphicon glyphicon-refresh"></i>
        <div ng-show="noResults">
          <i class="glyphicon glyphicon-remove"></i> No Results Found
        </div>
        <span class="input-group-btn">
            <button class="btn btn-default" name="search" …
Run Code Online (Sandbox Code Playgroud)

javascript angularjs angular-ui-bootstrap angular-ui-typeahead

11
推荐指数
1
解决办法
6844
查看次数