<!DOCTYPE html>
<html data-ng-app="myApp">
<head lang="en">
<meta charset="utf-8">
<title>AngularJS onclick Polling Spring MVC</title>
<script
	src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.26/angular.min.js"></script>
<script type="text/javascript">

    var app = angular.module('myApp', []);
    
    app.controller('MyController', function($scope, $http, $timeout) {    	
    	
		$scope.value = 1;
			
			$scope.callFunction = function() {
				polling();
			};
			var polling = function() {
				var value = $http({
					method : 'GET',
					url : 'pollDataFromServer'
				});
	
				value.success(function(data, status, headers, config) {
					$scope.randomNumber = data;
				});
	
				$timeout(function() {
					$scope.value++;
					polling();
				}, 1000);
			};			
	});
</script>
</head>

<body data-ng-controller="MyController">
	<h3>AngularJS onclick Polling Spring MVC</h3>

	<div>
		<button data-ng-click="callFunction();">Click button to activate polling from server</button>
		<p>Random Number from server on every call: {{randomNumber}} </p>	
		<p>Call made to the server: {{value}} Times</p>		
	</div>
	
</body>
</html>