Angular 1 Change Detection

by Preetha Srinivasan

HTML

<div ng-controller="ctrl">
  Hello, {{name}}!
</div>

JavaScript

var myApp = angular.module('myApp',[]);

function ctrl($scope) {
    $scope.name = 'Superhero';
    
    setTimeout(function(){ 
      $scope.name = 'Supehero Modified';
    },0)
    
    // The following piece of code updates the UI with the modified name
    /*setTimeout(function(){ 
      $scope.$apply(function(){
       $scope.name = 'Supehero Modified';
      });
    },0)*/
}