I am trying to search on the server side a name entered by the user, and give suggestions using bootstrap 3 uib-typeahead, however (although I hard coded the values to return - for testing purposes), no value is returning to the typeahead dropdown. My guess is that since this is an async request, any data is already returned by the time the request data is retrieved.
Is there any way how data could be retrieved from server side, whilst typeahead is listening?
$scope.test_search = function(test_name){
var curr_url = '/plan/ajax/test/';
var search_response = $http.get(curr_url,{
cache: true,
params:{'name': test_name, 'csrfmiddlewaretoken': $cookies.csrftoken}
}).then(function successCallback(response) {
console.log(response.data);
//return response.data;
var test = [
{country: "US", name : 'Alabama'}
];
return test;
}, function errorCallback(response) {
alert('Error');
});
},
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div class="col-lg-6">
<pre>Model: {{new_ingredient_selected | json}}</pre>
<input type="text"
ng-model = "new_ingredient_selected"
placeholder="test test"
uib-typeahead="ingredient.name for ingredient in test_search($viewValue) | filter:{name:$viewValue}"
typeahead-loading="loadingLocations"
typeahead-no-results="noResults"
typeahead-on-select="onTypeaheadIngredientSelect($item, $label, $index)"
typeahead-wait-ms ="400"
class="form-control">
<i ng-show="loadingLocations" class="glyphicon glyphicon-refresh"></i>
<div ng-show="noResults">
<i class="glyphicon glyphicon-remove"></i> No Results Found
</div>
</div>