Patrick Patrick - 4 months ago 16
Javascript Question

autocomplete using angularjs (not able to get input value)

I have the following plunker attached herewith
http://plnkr.co/edit/NPpjRM54vPu56GH9N1kI?p=preview

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.

Answer

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 ) {
    $scope.data = ui.item.value;
  }
});
Comments