我很确定我做得对,所以我不知道为什么它不起作用,也许我错过了一些明显的东西。这是应该具有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>
然后在后端我这样做:
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什么也没做。是什么给了什么?
谢谢:)
答案 0 :(得分:0)
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;
};