Reputation: 3486
How do I set a $watch on the selectedvalue property of a SELECT element in an angular directive? What is the syntax? I have a partial directive below. It doesn't blow up, but the watch never fires.
link: function (scope, elem, attr, ngModel) {
scope.$watch(elem.context.selectedOptions, function (selectedType) {
console.log("nodup choice");
})
}
Upvotes: 1
Views: 510
Reputation: 136144
I don't see a need here to put a watcher over an select
dropdown to fire something on its value change. I'd suggest you to use ng-change
event over that select box & have function over it. So that will get fire whenever input value gets changed.
<select ng-model="selectedValue" ng-change="changeFn()">
<option value="1"></option>
<option value="2"></option>
<option value="3"></option>
</select>
Upvotes: 2