UIB Typehead不显示下拉列表

时间:2016-10-16 18:26:47

标签: angularjs twitter-bootstrap angular-ui-bootstrap angular-ui-typeahead typehead

我有一个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上使用相同的sintax并且效果很好,但在打字头上没有。

编辑:啊,当然,HTTP获得了类似的ARRAY [{userName:Pedro},{userName:Maria},...]

2 个答案:

答案 0 :(得分:1)

获取用户必须返回承诺。试试这个:

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

    return $http({
...

答案 1 :(得分:0)

好的,我终于找到了答案,我错过了$ 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")
            })
    }
相关问题