用AngularJS提前输入

用AngularJS提前输入,angularjs,angular-ui-bootstrap,typeahead,Angularjs,Angular Ui Bootstrap,Typeahead,我正试图通过typeahead向我的项目中添加AutoMLETE,但现在它显示在下拉列表[object]中。我错在哪里 $scope.getUsers = function () { $scope.searchRequest = "/listaccounts.php?name=" + $scope.asyncSelected; console.log($scope.searchRequest); return $http.get($scope.se

我正试图通过typeahead向我的项目中添加AutoMLETE,但现在它显示在下拉列表[object]中。我错在哪里

$scope.getUsers = function () {
        $scope.searchRequest = "/listaccounts.php?name=" + $scope.asyncSelected;
        console.log($scope.searchRequest);
        return $http.get($scope.searchRequest).then(function (response) {
            $scope.searchResults = response.data;
            return $scope.searchResults.records;
        });
    };

<input type="text" ng-model="asyncSelected" ng-change="asyncSelected = asyncSelected.toLowerCase()" name="user" class="form-control" aria-describedby="basic-addon1" autocomplete="off" uib-typeahead="name for name in getUsers($viewValue)">
我只需要在下拉列表中显示姓名。

试试这个

 uib-typeahead="name.name as name.name for name in getUsers($viewValue)">
getUsers正在返回一个对象数组,typeahead似乎对此有问题。@hadiJz解决方案是否有效我不知道,或者您可以通过更改为从getUsers返回字符串列表:

return $scope.searchResults.records.map(function(record) { return record.name; }));
你可以

 <input name="records" id="records" type="text" placeholder="enter a record" ng-model="selected" typeahead="record.name for record in records | filter:$viewValue | limitTo:8" class="form-control">
这应该适用于getUsers$viewValue中用户的uib typeahead=user as user.name
 <input name="records" id="records" type="text" placeholder="enter a record" ng-model="selected" typeahead="record.name for record in records | filter:$viewValue | limitTo:8" class="form-control">