0

This is related to my previous question : Angular typeahead : watch for dataset change

I am using Siyfion's typeahead directive for my project since its a few lines of code simple to understand (for beginners like me ).

Now I have a django backend server which returns JSON objects which I would like to use for autocomplete.

Right now my controller looks like this :

$scope.getGuests = function (guestValue) {
  return $http.jsonp('http://gd.geobytes.com/AutoCompleteCity?callback=JSON_CALLBACK &filter=US&q=' + guestValue)
    .then(function (response) {
      return limitToFilter(response.data, 15);
    });
};

My markup :

<input type="text" class='sfTypeahead' datasets='getGuests($viewValue)' ngModel='testname' />

Now this obviously doesn't work because my widget doesn't load until it has datasets ready completely.
Is there a way where I can write directives such that I can use them like how its shown above ?

Community
  • 1
  • 1
Deepankar Bajpeyi
  • 5,661
  • 11
  • 44
  • 64

1 Answers1

1

Check if this works:

$scope.getGuests = function (guestValue) {
    var promise = $q.defer();
    $http.jsonp('http://gd.geobytes.com/AutoCompleteCity?
    callback=JSON_CALLBACK &filter=US&q=' + guestValue)
    .success(function (response) {
        promise.resolve(limitToFilter(response, 15));
    });
    return promise.promise;
};
AlwaysALearner
  • 43,759
  • 9
  • 96
  • 78