Skip to content Skip to sidebar Skip to footer

Call Controller Function From Select Angularjs

I was wondering how I can call a function in my controller depending on the option that is selected in a menu. For instance, using ng-click, when a is clicked, I can call the fun

Solution 1:

Use ng-change with ng-model:

 <select ng-model="model" ng-change="onSelect()" >

Where onSelect() is a method on your scope.

Solution 2:

<selectng-model="whatever"><optionvalue="settings">Settings</option></select>

In your controller:

$scope.$watch('whatever', function(newValue, oldValue) {
     if (newValue == 'settings') { 
         doSomething();
     }
});

Post a Comment for "Call Controller Function From Select Angularjs"