Domanda

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.

È stato utile?

Soluzione

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

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top