Skip to content

Instantly share code, notes, and snippets.

@karthickvkumar
Created May 23, 2017 12:32
Show Gist options
  • Select an option

  • Save karthickvkumar/638ef98f035d79620353da37cabc810e to your computer and use it in GitHub Desktop.

Select an option

Save karthickvkumar/638ef98f035d79620353da37cabc810e to your computer and use it in GitHub Desktop.

Revisions

  1. karthickvkumar created this gist May 23, 2017.
    31 changes: 31 additions & 0 deletions agular_digest_Loop.html
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,31 @@
    <!DOCTYPE html>
    <html>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
    <body>
    <div ng-app="myApp" ng-controller="myCtrl">
    {{data.time}}
    <br/>
    <button ng-click="updateTime()">update time - ng-click</button>
    <button id="updateTimeButton" >update time</button>
    </div>
    <script>
    var app = angular.module('myApp', []);
    app.controller('myCtrl', function($scope) {
    $scope.data = { time : new Date() };

    $scope.updateTime = function() {
    $scope.data.time = new Date();
    console.info($scope.data.time)
    }
    document.getElementById("updateTimeButton")
    .addEventListener('click', function(){
    $scope.data.time = new Date();
    /* $scope.$digest() //or
    $scope.$apply(function() {
    $scope.data.time = new Date();
    });*/
    })
    });
    </script>
    </body>
    </html>