Execute
<!DOCTYPE html> <html> <head> <title>Wikitechy AngularJS Tutorials</title> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js"> </script> </head> <body> <div ng-app="myApp" ng-controller="timeCtrl"> <h3>Wikitechy $interval Service </h3> <input type="button" value="Start" ng-click="Start()" /> <input type="button" value="Stop" ng-click="Stop()" /> <input type="button" value="Reset" ng-click="Reset()" /> <h3> {{time}} </h3> </div> <script> var app = angular.module("myApp", []); app.controller("timeCtrl", function($scope, $interval) { $scope.time = 0; $scope.Start = function () { $scope.Timer = $interval(function () { $scope.time = $scope.time+1; }, 100); }; $scope.Stop = function () { if (angular.isDefined($scope.Timer)) { $interval.cancel($scope.Timer); } }; $scope.Reset = function () { $scope.time = 0; }; }); </script> </body> </html>
www.wikitechy.com © Copyright 2016. All Rights Reserved.