Reputation: 3474
I use this code:
$scope.$watch('message', function()
{
// the code
});
Is there any way to fire change event of message manually, so the code will be executed?
Upvotes: 27
Views: 29851
Reputation: 8091
Another option here is declaring the function separately and using $scope.watch
with the pointer.
var watchFunction = function(){
// the code
}
$scope.$watch('message',watchFunction);
watchFunction();
Upvotes: 12
Reputation: 8948
Few options:
Use $scope.$apply() to run the digest loop which call all of the watch expressions
Put you inner watch code inside a function and call it manually
Change messages
:)
Upvotes: 42