|
89 | 89 | <ul class="dropdown-menu">
|
90 | 90 | <li><a href="examples.html#angularjs-single-timer">AngularJS - Single Timer</a></li>
|
91 | 91 | <li><a href="examples.html#angularjs-multiple-timer">AngularJS - Multiple Timers</a></li>
|
| 92 | + <li><a href="examples.html#angularjs-polling-timer">AngularJS - Polling Timers</a></li> |
92 | 93 | <li><a href="examples.html#jquery-timer">jQuery</a></li>
|
93 | 94 | <li><a href="examples.html#plain-javascript">Plain JavaScript</a></li>
|
94 | 95 | </ul>
|
@@ -213,6 +214,81 @@ <h3>AngularJS - Multiple Timer</h3>
|
213 | 214 | </div>
|
214 | 215 | </section>
|
215 | 216 |
|
| 217 | + <section id="angularjs-polling-timer"> |
| 218 | + <h3>AngularJS - Polling Timers</h3> |
| 219 | + <ul class="nav nav-tabs" id="angularjs-polling-timer-tab"> |
| 220 | + <li class="active"><a data-toggle="tab" href="#angularjs-polling-timer-source">index.html</a></li> |
| 221 | + <li><a data-toggle="tab" href="#angularjs-polling-timer-demo">Demo</a></li> |
| 222 | + </ul> |
| 223 | + |
| 224 | + <div class="tab-content"> |
| 225 | + <div class="tab-pane active" id="angularjs-polling-timer-source"> |
| 226 | + <pre class="prettyprint linenums"> |
| 227 | +<!DOCTYPE html> |
| 228 | +<html> |
| 229 | +<head> |
| 230 | + <title>AngularJS Example - Polling Timer Example</title> |
| 231 | + <script src="../angular/angular.min.js"></script> |
| 232 | + <script src="../app/js/timer.js"></script> |
| 233 | + <script> |
| 234 | + angular.module('MyApp', ['timer']); |
| 235 | + function PollingController($scope) { |
| 236 | + $scope.timerRunning = true; |
| 237 | + $scope.timerConsole = ''; |
| 238 | + |
| 239 | + $scope.timerType = ''; |
| 240 | + |
| 241 | + $scope.startTimer = function (){ |
| 242 | + $scope.$broadcast('timer-start'); |
| 243 | + $scope.timerRunning = true; |
| 244 | + }; |
| 245 | + |
| 246 | + $scope.stopTimer = function (){ |
| 247 | + $scope.$broadcast('timer-stop'); |
| 248 | + $scope.timerRunning = false; |
| 249 | + }; |
| 250 | + |
| 251 | + $scope.$on('timer-tick', function (event, args) { |
| 252 | + $scope.timerConsole += $scope.timerType + ' - event.name = '+ event.name + ', timeoutId = ' + args.timeoutId.$$timeoutId + ', millis = ' + args.millis +'\n'; |
| 253 | + }); |
| 254 | + } |
| 255 | + |
| 256 | + PollingController.$inject = ['$scope']; |
| 257 | + </script> |
| 258 | +</head> |
| 259 | +<body ng-app="MyApp"> |
| 260 | + <div> |
| 261 | + <h1>AngularJS - Polling Timer Example using <code>timer-tick</code> event</h1> |
| 262 | + <div ng-init="timerType = 'Polling Server'" ng-controller="PollingController" style="border: 1px darkgray dashed; padding: 15px;margin:15px"> |
| 263 | + <h2>Polling Server every 5 seconds</h2> |
| 264 | + <h3><timer interval="5000"/></h3> |
| 265 | + <textarea style="height: 100px;" row=20 cols="200">{{timerConsole}}</textarea> |
| 266 | + <br/> |
| 267 | + <button ng-click="startTimer('poll-server')" ng-disabled="timerRunning">Start Timer</button> |
| 268 | + <button ng-click="stopTimer('poll-server')" ng-disabled="!timerRunning">Stop Timer</button> |
| 269 | + </div> |
| 270 | + <br/> |
| 271 | + |
| 272 | + <div ng-init="timerType = 'Saving Documents'" ng-controller="PollingController" style="border: 1px darkgray dashed; padding: 15px"> |
| 273 | + <h2>Saving Document every 3 seconds</h2> |
| 274 | + <h3><timer interval="3000"/></h3> |
| 275 | + <textarea style="height: 100px;" row=20 cols="200">{{timerConsole}}</textarea> |
| 276 | + <br/> |
| 277 | + <button ng-click="startTimer('poll-server')" ng-disabled="timerRunning">Start Timer</button> |
| 278 | + <button ng-click="stopTimer('poll-server')" ng-disabled="!timerRunning">Stop Timer</button> |
| 279 | + </div> |
| 280 | + |
| 281 | + </div> |
| 282 | + <br/> |
| 283 | +</body> |
| 284 | +</html></pre> |
| 285 | + </div> |
| 286 | + <div class="tab-pane" id="angularjs-polling-timer-demo"> |
| 287 | + <iframe src="examples/angularjs-polling-timer.html" width="100%" height="350px"></iframe> |
| 288 | + </div> |
| 289 | + </div> |
| 290 | + </section> |
| 291 | + |
216 | 292 | <section id="jquery-timer">
|
217 | 293 | <h3>JQuery Timer</h3>
|
218 | 294 | <ul class="nav nav-tabs" id="jquery-timer-tab">
|
|
0 commit comments