aspdotnet-suresh offers articles and tutorials,csharp dot net, articles and tutorials,VB.NET Articles,Gridview articles,code examples of 2.0 /3.5,AJAX,SQL Server Articles,examples of .net technologies

Angularjs $interval Example to Refresh Div for Every n Seconds

May 11, 2015

Here I will explain how to refresh div for every 1 second using $interval in 
AngularJS with example. Generally in JavaScript we will use setInterval() function to run our code for every specific period of time same way in AngularJS we have $interval angular module to do same functionality like setInterval() function. To refresh div for every 1 second here I am going to use $interval angular module.

In previous articles I explained jQuery setInterval() function example, start and stop time in javascript using setInterval function, jQuery redirect to another page after 5 seconds, Javascript redirect to another page after 5 seconds and many articles relating to
jQuery, JavaScript and Now I will explain how to refresh div for every 1 second using AngularJS.

To refresh div for every 1 second we need to write the code like as shown below

<html xmlns="">
<title>Refresh Div for every 1 second using Angularjs</title>
<script src=""></script>
<script type="text/javascript">
var app = angular.module('sampleapp', [])
app.controller('samplecontrol', function($scope, $interval) {
var i = 0;
var timer;
$scope.message = "DIV is refreshed at " + i + " seconds.";
$scope.starttimer = function() {
timer = $interval(function() {
$scope.message = "DIV is refreshed at " + i + " seconds.";
}, 1000)
$scope.stoptimer = function() {
if (angular.isDefined(timer)) {
timer = undefined;
$scope.message = "Timer is killed :-(";
<form id="form1">
<div data-ng-app="sampleapp" data-ng-controller="samplecontrol">
<input type="button" id="btnStart" data-ng-click="starttimer()" value="Start" />
<input type="button" id="btnStop" data-ng-click="stoptimer()" value="Stop"/>
Live Demo

To check live demo try to click on below buttons to start and stop timer


If you enjoyed this post, please support the blog below. It's FREE!

Get the latest,, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email.

subscribe by rss Subscribe by RSS subscribe by email Subscribe by Email


Give your Valuable Comments

Other Related Posts

© 2015 All Rights Reserved.
The content is copyrighted to Suresh Dasari and may not be reproduced on other websites without permission from the owner.