$apply() Function using Angular Example

Today, We want to share with you $apply() Function using Angular Example.In this post we will show you Angularjs $scope.$apply() function example, hear for How to use angularjs $apply() function with example we will give you demo and example for implement.In this post, we will learn about $scope.apply is not a function with an example.

$apply() Function using Angular Example

There are the Following The simple About $scope.apply is not a function Full Information With Example and source code.

As I will cover this Post with live Working example to develop Angularjs centralized function scope.$apply with example, so the digest already in progress is used for this example is following below.

Read Also:  jquery remove last comma from Array Example

AngularJs $apply() Function Example

Angular is a platform for building mobile & desktop web Based user friendly and light weight applications.Angular,It’s TypeScript-based open-source Angularjs web application framework.

index.html

<!DOCTYPE html>
<html>
<head>
<title>
AngularJs $apply() Function with Example - https://www.pakainfo.com/
</title>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<script type="text/javascript">
var angularTutorialApp = angular.module('applyModule', []);
angularTutorialApp.controller('applyController', function ($scope) {
$scope.liveActiveTimeStemp = new Date();
$scope.changeNewTimeZone = function () {
$scope.liveActiveTimeStemp = new Date();
}
//Added an event listener.
var event = document.getElementById("btnapply");
event.addEventListener('click', function () {
//The $apply method is use to update date time on rootScope forcefully.
$scope.$apply(function () {
//get dateTime
$scope.liveActiveTimeStemp = new Date();
});
});
});
</script>
</head>
<body>
<div ng-app="applyModule" ng-controller="applyController">
<h2>AngularJS $apply() Function Example</h2>
<input type="button" value="Click to Update DateTime" ng-click="changeNewTimeZone()" />
<input type="button" value="Click to Update DateTime forcefully." id="btnapply" />
<br /><br />
<span style="color:Red">Current Date Time: {{liveActiveTimeStemp | date:'yyyy-MM-dd HH:mm:ss'}}</span>
</div>
</body>
</html>

Web Programming Tutorials Example with Demo

Read :

Read Also:  $digest() Function using Angular Example

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about watch in angularjs example.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.