Patrick Patrick - 3 months ago 11
Javascript Question

autocomplete using angularjs (not able to get input value)

I have the following plunker attached herewith

As you can see, there is a list of available tags. If i write 'a' in the input field, several autocomplete items show up below.

If i keep typing, i can see what i have typed beside it using the below code

<input id="tags" ng-keyup="complete()" ng-model="data" /> selected = {{data}}

But instead of typing, i just select 'ActionScript' in its dropdown from autocomplete, it doesnot get updated to ng-model.

Can someone let me know how to select from the dropdown and have it updated to the ng-model as well.


According to the Autocomplete docs, there's an "select" event that will do what you need:

$( "#tags" ).autocomplete({
  source: $scope.availableTags,
  select: function( event, ui ) {
    $ = ui.item.value;