How to call a function in the case given below?
<select class="dropdown">
<option ng-repeat="group in myGroups" ng-model="group.Name" ng-change="myFunction(group.Id)">{{group.Name}}</option>
</select>
So, how can I call a function inside ng-repeat select? (its not ng-select as you probably noticed)
Well, the option
itself does not change.
What changes is the value of the select
element.
So, try this:
<select ng-model="selectedGroup" ng-change="yourFunction()">
<option ng-repeat="group in myGroups">{{group.name}}</option>
</select>
with a yourFunction
on the current scope
like this:
scope.yourFunction = function() {
console.log(scope.selectedGroup);
};
I also strongly suggest you have a look at ngOptions
here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With