scope.$watch doesn't work in directive
Frage
I have custom angularjs directive and click
handler in it like:
element.bind('click', function () {
scope.checked = !scope.checked;
});
And i want to catch when scope.checked
is changing, i'm trying to so with:
scope.$watch(scope.checked, function(val){
console.log(val);
});
But i don't see anything.
Thank you.
Lösung
Just a typo; it's:
scope.$watch('checked', function(val){
console.log(val);
});
Reference: http://code.angularjs.org/1.2.16/docs/api/ng/type/$rootScope.Scope#$watch
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow