0

I'm trying to add autocomlete by typeahead to my project, but now it shows in the Dropdown [object Object]. Where am I wrong?

$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)">

JSON looks like:

{"records":[{"name":"q2q23w"},{"name":"qantheman"},{"name":"qee"},{"name":"qit"},{"name":"qiwi"}]}

I need to show in the dropdown only names.

1
  • This should work with uib-typeahead="user as user.name for user in getUsers($viewValue)" Commented Jan 28, 2017 at 9:41

3 Answers 3

1

getUsers() is returning an array of objects and typeahead seems to have problem with this. Either @hadiJz solution will work (I don't know) or you could return a list of strings from getUsers() by changing to:

return $scope.searchResults.records.map(function(record) { return record.name; }));
Sign up to request clarification or add additional context in comments.

Comments

0

Try this

 uib-typeahead="name.name as name.name for name in getUsers($viewValue)">

Comments

0

You can do,

 <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">

DEMO

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.