Search code examples
angularjsautocompleteangularjs-material

How to handle item select in AngularJS Autocomplete


I am very new to AngularJS..

I managed to implement Autocomplete control by using example

https://material.angularjs.org/latest/demo/autocomplete

Unfortunately it is only part of my control. And now I have tried everything but I can't get how to handle the event when an item get selected.

I am trying to implement multiple selects one depending on selected value of another.

Thanks!


Solution

  • You can use md-selected-item-change attribute

    md-selected-item-change expression An expression to be run each time a new item is selected

    eg:

    <md-autocomplete
              ...
              md-selected-item-change="selectedItemChange(item)">
    </md-autocomplete>
    

    js:

    $scope.selectedItemChange = function(item) {
      $log.info('Item changed to ' + JSON.stringify(item));
    }