【问题标题】:AngularUI Typeahead not showing async dataAngularUI Typeahead 不显示异步数据
【发布时间】:2015-06-25 18:08:36
【问题描述】:

我很确定我做对了,所以我不知道为什么它不起作用,也许我错过了一些明显的东西。这是应该预先输入的输入:

<input type="text" class="form-control" typeahead-min-length="4" typeahead-loading="loadingLocations" ng-model="modal.modalObject.facility_id" ng-required="true" typeahead="fac.id as fac.facility_name for fac in modal.parentCtrl.queryFacilities($viewValue)" />
<i ng-show="loadingLocations" class="glyphicon glyphicon-refresh"></i>

然后在后端我这样做:

this.queryFacilities = function(query){
   qualificationFactory.queryFacilities(query).then(function(data){
        return data;
    },function(error){
        $log.error(error);
    });
};

返回的是什么

[
  {
    "id": 1,
    "facility_name": "Facility 1",
    "address": "",
    "city": "",
    "state": "",
    "zip": 012345
  },
  {
      ...
    }
]

我在输入时可以看到 http 请求成功,但是 intput 什么也没做。什么给了?

谢谢:)

【问题讨论】:

    标签: angular-ui typeahead angular-bootstrap angular-ui-typeahead


    【解决方案1】:

    我不得不将值作为承诺返回,因为queryFacilities 没有返回 http 内部的返回值

    this.queryFacilities = function(query){
        var deferred = $q.defer();
       qualificationFactory.queryFacilities(query).then(function(data){
            deferred.resolve(data);
        },function(error){
            deferred.reject(error);
            $log.error(error);
        });
        return deferred.promise;
    };
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-09-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-30
      • 1970-01-01
      相关资源
      最近更新 更多