Skip to content

Instantly share code, notes, and snippets.

@karthickvkumar
Created May 23, 2017 12:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save karthickvkumar/638ef98f035d79620353da37cabc810e to your computer and use it in GitHub Desktop.
Save karthickvkumar/638ef98f035d79620353da37cabc810e to your computer and use it in GitHub Desktop.
<!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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment