Understanding $apply () and $digest () in angular
<!DOCTYPE HTML><HTML><Head> <MetaCharSet= "Utf-8"> <title></title></Head><BodyNg-app= "MYAPP"> <DivNg-controller= "Messagecontroller">Delayed message: {{Message}}</Div>you should use the $timeout service instead of settimeout (), because the former will help you call $apply (), so you don't need to call it manually<Scriptsrc= "Angular.min.js"></Script> <Script>Angular.module ('myApp', []). Controller ('Messagecontroller', function($scope) {$scope. GetMessage= function() { /*setTimeout (function () {$scope. Message = ' fetched after 3 seconds '; Console.log (' message: ' + $scope. message); }, 2000); */SetTimeout (function() {$scope. $apply (function() { //wrapped this within $apply$scope. Message= 'fetched after 3 seconds'; Console.log ('message:' +$scope. Message); }); }, -); } $scope. GetMessage (); }); </Script></Body></HTML>
$apply () $digest ()