Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
62
rated 0 times [  66] [ 4]  / answers: 1 / hits: 85198  / 12 Years ago, mon, february 4, 2013, 12:00:00

I am trying to watch my model value from inside my linking function.



scope.$watch(attrs.ngModel, function() {
console.log(Changed);
});


When I change the model value inside my controller, the $watch function is not triggered.



$scope.myModel = ACT;

$timeout(function() {
$scope.myModel = TOTALS;
}, 2000);


Fiddle: http://jsfiddle.net/dkrotts/BtrZH/4/



What am I missing here?


More From » angularjs

 Answers
32

The problem is that you $watching attrs.ngModel which is equal to myModel. You do not have myModel bound in your scope. You want to $watch model. That is what is bound in the scope of your directive. See http://jsfiddle.net/BtrZH/5/


[#80429] Saturday, February 2, 2013, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
darrell

Total Points: 109
Total Questions: 113
Total Answers: 113

Location: Zambia
Member since Sat, Oct 31, 2020
4 Years ago
;