I have the following uib-typeahead markup:
<input type="text" class="form-control" id="field_location" ng-model="surveyData.location"
placeholder="Search"
uib-typeahead="location as location.name for location in newListLocations | filter:$viewValue:customSearch | orderBy:location.country.name | limitTo:200"
typeahead-editable="false">
And I update it with a REST call that works perfectly in the back-end, and here's how I consume it in the controller (taken from this question):
$scope.filterLocations = function(searchValue, viewValue) {
var newListOfLocations = LocationTypeaheadFilter.queryWithTypeaheadSearchValue(viewValue).then(function (list){
$scope.newListLocations = list.data;
console.log($scope.newListLocations);
return $scope.newListLocations;
},
function errorCallback(response) {
alert('Error');
throw response;
});
return newListOfLocations;
};
This function is called using this the original one from the markup:
$scope.customSearch = function(searchValue, viewValue){
return $scope.filterLocations(searchValue, viewValue);}
I tried at first putting all the logic in one same method, but no difference, the list for the typeahead always turns up empty, even though when I log it on console in the .then
area, it shows all values I expect it to hold.
I've tried a number of different ways, but I believe that it should work the way I've coded it, provided I'm waiting for the callback
EDIT to add the factory where I defined the Angular service:
.factory('LocationTypeaheadFilter', function ($http, DateUtils) {
return {
queryWithTypeaheadSearchValue: function(query){
return $http.get("api/locationssearchTypeahead/"+query)
}
}});
答案 0 :(得分:0)
我注意到你正在使用location as location.name
,然后在同一个表达式中使用orderBy:location.country.name
。 location.name
是有效路径吗?
您的意思是location as location.country.name
吗?如果出错,将导致列表空白。
如果您可以在问题中添加位置数据样本,那么有助于找出问题所在。