UIB Typeahead 不显示下拉菜单

UIB Typehead dont show the dropdown

我有一个 UI-Bootstrap 的打字头,但是当收到数据时,下拉列表不显示。

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

还有 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>

我在 ng-options 上使用相同的语法,效果很好,但在打字头上却不行。

编辑:啊,当然,HTTP 获取这样的 ARRAY [{userName: Pedro}, {userName: Maria}, ...]

好吧我终于找到答案了,我在$http

后面漏了一个RETURN

HTML:

  uib-typeahead="nombreUsuario.nombreUsuario for nombreUsuario in obtenerUsuarios($viewValue)"

JS:

    $scope.obtenerUsuarios = function (valor) {
        return  $http({
                method: "POST",
                url: "http://localhost:3000/obtenerUsuarios",
                params: {"valor": valor}
            }).then(function successCallback(response){
                return response.data;
            }, function errorCallback(error){
                alert("No se han podido enviar los datos")
            })
    }

obtainUsers 必须return 承诺。试试这个:

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

    return $http({
...