/ / associazione dati bidirezionale con watch - angularjs, direttiva angularjs, angularjs-scope

associazione dati bidirezionale con watch - angularjs, direttiva angularjs, angularjs-scope

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 № 1

Perfavore 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);
});
}
}