How To Make Angular Uib-typeahead To Show Suggestions Immediately After Binding The Model?

- 1 answer

I'm implementing a search here. When user enters a character in input box, on ng-chanage event I hit the api, get the model and bind it to uib-typehead. Now what I want is that when I bind the model uib-typehead, it should immediately start suggesting options for the already entered characters in the input box just like google does. Instead of doing so, it keeps on waiting for the next character so that event could be triggered.

Note: I stop hitting the API after entering 2 characters.

Input code

<input id="tbSearchBox" name="tbSearchBox" type="text" ng-model="selected" ng-change="keyPressed()" uib-typeahead="x.x for x in securities | filter:$viewValue | limitTo:8" typeahead-on-select="selectedSecurity($item, $model, $label)">

In above code ng-change is allowing me to capture the event whenever the text is changed and hit the API to get the model.

I checked web for various solution like show suggestions on focus or button click but none of them is post model binding trigger. There could be some hack but I want the best one and purely angular oriented. Don't wanna use jQuery jsut for this situation.




I've been seeking for the answer however there was not any direct solution. I somehow managed to find a trick here to get it done. Programmatically by making enter/click on which the event triggers for textbox, it is working.

$scope.$watch("securities", function () {

Now whenever the model changes it adds trigger that serves the purpose.