AngularUI Typeahead not showing async data

203 views Asked by At

I'm pretty sure I'm doing this right so I don't know why it's not working, maybe I'm missing something obvious. Here's the input that is supposed to have typeahead:

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

And then in the back end I'm doing this:

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

Which is returning

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

I can see the http request succceed when I type, but the intput does nothing. What gives?

Thanks :)

1

There are 1 answers

0
Z2VvZ3Vp On

I had to return the value as a promise because the return inside of the http was not getting returned by queryFacilities

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;
};