Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d35f50e

Browse files
committed
docs($interval): update example to use a module
1 parent 74014f5 commit d35f50e

File tree

1 file changed

+40
-39
lines changed

1 file changed

+40
-39
lines changed

src/ng/interval.js

Lines changed: 40 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -42,25 +42,27 @@ function $IntervalProvider() {
4242
* @returns {promise} A promise which will be notified on each iteration.
4343
*
4444
* @example
45-
* <example module="time">
46-
* <file name="index.html">
47-
* <script>
48-
* function Ctrl2($scope,$interval) {
49-
* $scope.format = 'M/d/yy h:mm:ss a';
50-
* $scope.blood_1 = 100;
51-
* $scope.blood_2 = 120;
52-
*
53-
* var stop;
54-
* $scope.fight = function() {
55-
* // Don't start a new fight if we are already fighting
56-
* if ( angular.isDefined(stop) ) return;
45+
* <example module="intervalExample">
46+
* <file name="index.html">
47+
* <script>
48+
* angular.module('intervalExample', [])
49+
* .controller('ExampleController', ['$scope', '$interval',
50+
* function($scope, $interval) {
51+
* $scope.format = 'M/d/yy h:mm:ss a';
52+
* $scope.blood_1 = 100;
53+
* $scope.blood_2 = 120;
54+
*
55+
* var stop;
56+
* $scope.fight = function() {
57+
* // Don't start a new fight if we are already fighting
58+
* if ( angular.isDefined(stop) ) return;
5759
*
5860
* stop = $interval(function() {
5961
* if ($scope.blood_1 > 0 && $scope.blood_2 > 0) {
60-
* $scope.blood_1 = $scope.blood_1 - 3;
61-
* $scope.blood_2 = $scope.blood_2 - 4;
62+
* $scope.blood_1 = $scope.blood_1 - 3;
63+
* $scope.blood_2 = $scope.blood_2 - 4;
6264
* } else {
63-
* $scope.stopFight();
65+
* $scope.stopFight();
6466
* }
6567
* }, 100);
6668
* };
@@ -75,22 +77,21 @@ function $IntervalProvider() {
7577
* $scope.resetFight = function() {
7678
* $scope.blood_1 = 100;
7779
* $scope.blood_2 = 120;
78-
* }
80+
* };
7981
*
8082
* $scope.$on('$destroy', function() {
81-
* // Make sure that the interval is destroyed too
83+
* // Make sure that the interval nis destroyed too
8284
* $scope.stopFight();
8385
* });
84-
* }
85-
*
86-
* angular.module('time', [])
87-
* // Register the 'myCurrentTime' directive factory method.
88-
* // We inject $interval and dateFilter service since the factory method is DI.
89-
* .directive('myCurrentTime', function($interval, dateFilter) {
86+
* })
87+
* // Register the 'myCurrentTime' directive factory method.
88+
* // We inject $interval and dateFilter service since the factory method is DI.
89+
* .directive('myCurrentTime', ['$interval', 'dateFilter',
90+
* function($interval, dateFilter) {
9091
* // return the directive link function. (compile function not needed)
9192
* return function(scope, element, attrs) {
9293
* var format, // date format
93-
* stopTime; // so that we can cancel the time updates
94+
* stopTime; // so that we can cancel the time updates
9495
*
9596
* // used to update the UI
9697
* function updateTime() {
@@ -106,28 +107,28 @@ function $IntervalProvider() {
106107
* stopTime = $interval(updateTime, 1000);
107108
*
108109
* // listen on DOM destroy (removal) event, and cancel the next UI update
109-
* // to prevent updating time ofter the DOM element was removed.
110+
* // to prevent updating time after the DOM element was removed.
110111
* element.on('$destroy', function() {
111112
* $interval.cancel(stopTime);
112113
* });
113114
* }
114115
* });
115-
* </script>
116-
*
117-
* <div>
118-
* <div ng-controller="Ctrl2">
119-
* Date format: <input ng-model="format"> <hr/>
120-
* Current time is: <span my-current-time="format"></span>
121-
* <hr/>
122-
* Blood 1 : <font color='red'>{{blood_1}}</font>
123-
* Blood 2 : <font color='red'>{{blood_2}}</font>
124-
* <button type="button" data-ng-click="fight()">Fight</button>
125-
* <button type="button" data-ng-click="stopFight()">StopFight</button>
126-
* <button type="button" data-ng-click="resetFight()">resetFight</button>
127-
* </div>
116+
* </script>
117+
*
118+
* <div>
119+
* <div ng-controller="ExampleController">
120+
* Date format: <input ng-model="format"> <hr/>
121+
* Current time is: <span my-current-time="format"></span>
122+
* <hr/>
123+
* Blood 1 : <font color='red'>{{blood_1}}</font>
124+
* Blood 2 : <font color='red'>{{blood_2}}</font>
125+
* <button type="button" data-ng-click="fight()">Fight</button>
126+
* <button type="button" data-ng-click="stopFight()">StopFight</button>
127+
* <button type="button" data-ng-click="resetFight()">resetFight</button>
128128
* </div>
129+
* </div>
129130
*
130-
* </file>
131+
* </file>
131132
* </example>
132133
*/
133134
function interval(fn, delay, count, invokeApply) {

0 commit comments

Comments
 (0)