var app = angular.module('plunker', []);
app.controller('MainCtrl', function($scope) {
$scope.$watch(function () { },
function (newValue, oldValue, scope) {
scope.$apply(function () {
console.log('This will not work');
});
}
);
$scope.$watch(function () { },
function (newValue, oldValue, scope) {
scope.$applyAsync(function () {
console.log('This will work as you are using $applyAsync!');
});
}
);
});
<!DOCTYPE html>
<html ng-app="plunker">
<head>
<meta charset="utf-8" />
<title>Getting Inside Angular: $scope.$applyAsync</title>
<script>document.write('<base href="' + document.location + '" />');</script>
<link rel="stylesheet" href="style.css" />
<script data-require="angular.js@1.4.x" src="https://code.angularjs.org/1.4.3/angular.js" data-semver="1.4.3"></script>
<script src="app.js"></script>
</head>
<body ng-controller="MainCtrl">
<h1>Getting Inside Angular: $scope.$applyAsync</h1>
<a href="http://blog.theodybrothers.com/2015/08/getting-inside-angular-scopeapplyasync.html">
Read about it here
</a>
<p>And make sure you've opened your browser's console (developer tools)</p>
</body>
</html>
/* Put your css in here */
#Getting Inside Angular: Can a Digest Continue Forever?
[Read about it here](http://blog.theodybrothers.com/2015/11/getting-inside-angular-can-digest.html)
And make sure you've opened your browser's console (developer tools)