angularjstwitter-bootstrapangular-ui-bootstrapangular-ui-typeaheadtypehead

UIB Typehead dont show the dropdown


I have a typehead of UI-Bootstrap but when the data is received the dropdown dont show.

$scope.obtainUsers = function (valor) {
        console.log(valor)

            $http({
                method: "POST",
                url: "http://localhost:3000/obtainUsers",
                params: {"valor": valor}
            }).then(function successCallback(response){
                console.log(response.data);

                return response.data;

            }, function errorCallback(error){
                alert("ERROR")
            })
    }

And the HTML

                    <input type="text" ng-model="selectedValue" uib-typeahead="userName as userName.userName for userName in obtainUsers($viewValue)" typeahead-loading="loadingUsers" typeahead-no-results="noResults" class="form-control">
                    <i ng-show="loadingUsers" class="glyphicon glyphicon-refresh"></i>
                    <div ng-show="noResults">
                      <i class="glyphicon glyphicon-remove"></i> No Results Found
                    </div>

I use the same sintax on a ng-options and it works well, but no on the typehead.

EDIT: Ah, of course, the HTTP obtain an ARRAY like that [{userName: Pedro}, {userName: Maria}, ...]


Solution

  • obtainUsers must return the promise. Try this:

    $scope.obtainUsers = function (valor) {
        console.log(valor)
    
        return $http({
    ...