1+ <!DOCTYPE html>
2+ < html >
3+ < head >
4+ < title > AngularJS Example - Single Timer Example</ title >
5+ < script src ="../angular/angular.min.js "> </ script >
6+ < script src ="../app/js/timer.js "> </ script >
7+ < script >
8+ angular . module ( 'MyApp' , [ 'timer' ] ) ;
9+ function PollingController ( $scope , timerConsolePrefix ) {
10+ $scope . timerRunning = true ;
11+ $scope . timerConsole = '' ;
12+
13+ $scope . timerType = '' ;
14+
15+ $scope . startTimer = function ( ) {
16+ $scope . $broadcast ( 'timer-start' ) ;
17+ $scope . timerRunning = true ;
18+ } ;
19+
20+ $scope . stopTimer = function ( ) {
21+ $scope . $broadcast ( 'timer-stop' ) ;
22+ $scope . timerRunning = false ;
23+ } ;
24+
25+ $scope . $on ( 'timer-tick' , function ( event , args ) {
26+ $scope . timerConsole += $scope . timerType + ' - event.name = ' + event . name + ', timeoutId = ' + args . timeoutId . $$timeoutId + ', millis = ' + args . millis + '\n' ;
27+ } ) ;
28+ }
29+
30+ PollingController . $inject = [ '$scope' ] ;
31+ </ script >
32+ </ head >
33+ < body ng-app ="MyApp ">
34+ < div >
35+ < h1 > AngularJS - Timer With Events Example</ h1 >
36+ < div ng-init ="timerType = 'Polling Server' " ng-controller ="PollingController " style ="border: 1px darkgray dashed; padding: 15px ">
37+ < h2 > Example Simulating Polling Server every 5000 milliseconds</ h2 >
38+ < h3 > < timer interval ="5000 "/> </ h3 >
39+ < textarea style ="height: 100px; " row =20 cols ="200 "> {{timerConsole}}</ textarea >
40+ < br />
41+ < button ng-click ="startTimer('poll-server') " ng-disabled ="timerRunning "> Start Timer</ button >
42+ < button ng-click ="stopTimer('poll-server') " ng-disabled ="!timerRunning "> Stop Timer</ button >
43+ </ div >
44+
45+ < div ng-init ="timerType = 'Saving Documents' " ng-controller ="PollingController " style ="border: 1px darkgray dashed; padding: 15px ">
46+ < h2 > Example Simulating Saving Document every 3000 milliseconds</ h2 >
47+ < h3 > < timer interval ="3000 "/> </ h3 >
48+ < textarea style ="height: 100px; " row =20 cols ="200 "> {{timerConsole}}</ textarea >
49+ < br />
50+ < button ng-click ="startTimer('poll-server') " ng-disabled ="timerRunning "> Start Timer</ button >
51+ < button ng-click ="stopTimer('poll-server') " ng-disabled ="!timerRunning "> Stop Timer</ button >
52+ </ div >
53+
54+ </ div >
55+ < br />
56+ </ body >
57+ </ html >
0 commit comments