0

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

1 Answer 1

0

I notice you're using location as location.name, then later in the same expression you're using orderBy:location.country.name. Is location.name a valid path?

Did you mean location as location.country.name? Getting this wrong would result in a blank list.

If you could add a sample of the location data to your question, that would help find what's going wrong.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.