Thursday, March 10, 2016

Firing $watch event manually in angularjs


Firing $watch event manually in angularjs


We have few options:

  1. Use $scope.$apply() to run the digest loop which call all of the watch expressions.
  2. Put you inner watch code inside a function and call it manually.
  3. Change messages.

Explanation for second one:


var watchFunc = function(){
    // the code
}

$scope.$watch('message',watchFunc);

watchFunc();

No comments:

Post a Comment