【问题标题】:UIB Typehead dont show the dropdownUIB Typeahead 不显示下拉菜单
【发布时间】:2016-10-16 18:26:47
【问题描述】:

我有一个 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 获得一个这样的数组 [{用户名:佩德罗},{用户名:玛丽亚},...]

【问题讨论】:

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


    【解决方案1】:

    obtainUsers 必须返回承诺。试试这个:

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

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-05-27
        • 1970-01-01
        相关资源
        最近更新 更多