I have a directive on a element called on-change. The idea is when the selected value changes it gets saved in a scope variable and then another element picks it up.
My problem is if the elements of the are static the above works fine but if I use ng-repeat, the onchange stops working.
<select on-change="myvar" ng-repeat="(key, value) in dataset">
<option value="{{key}}">{{value.name}}</option>
</select>
here's my onchange directive:
.directive('onChange', function() {
return {
restrict: 'A',
scope:{'onChange':'=' },
link: function(scope, elm, attrs) {
scope.$watch('onChange', function(nVal) { elm.val(nVal); });
elm.bind('blur', function() {
var currentValue = elm.val();
if( scope.onChange !== currentValue ) {
scope.$apply(function() {
scope.onChange = currentValue;
});
}
});
}
};
})
Any idea's on how I can overcome this issue?
Thanks