How can I add a click listener to ng-select options?

If I create a select using Angular such as so:

<select multiple ng-model="selection" ng-options="option.name for option in getOptions()"></select>

How can I add an ng-click listener to each of the options? Is this possible, or would I have to just create the options myself using ng-repeat?

Upvotes: 3

Views: 3352

Answers (1)

Catalin MUNTEANU
Catalin MUNTEANU

Reputation: 5634

You can use ngChange directive:

<select multiple
        ng-change="update_select()"
        ng-model="selection"
        ng-options="option.name for option in getOptions()"></select>

And in your controller:

$scope.update_select = function() {
    console.log($scope.selection);
};

JSFiddle

Upvotes: 6

Related Questions