Perché $ scope.watch non funziona con "modello"? http://jsfiddle.net/lesouthern/8PUtP/5/
.directive("testDirective",function() {
return {
restrict : "A",
scope : {
model : "=ngModel"
},
link : function($scope,$element,$attrs) {
$scope.$watch("model",function(x) {
console.log("this is model: " + x);
});
}
}
});
risposte:
1 per risposta № 1Perfavore guarda questa domanda. Ecco il tuo codice corretto:
return {
restrict : "A",
link : function($scope, $element, $attrs) {
$scope.$watch($attrs.ngModel, function(x) {
console.log("this is model: " + x);
});
}
}