Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 13b5fd1

Browse files
xrdbtford
authored andcommitted
fix(docs): Fixed defer to timeout change in timer directive example
1 parent 17209d5 commit 13b5fd1

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

docs/content/guide/directive.ngdoc

+7-7
Original file line numberDiff line numberDiff line change
@@ -178,12 +178,12 @@ In this example we will build a directive which displays the current time.
178178

179179
angular.module('time', [])
180180
// Register the 'myCurrentTime' directive factory method.
181-
// We inject $defer and dateFilter service since the factory method is DI.
182-
.directive('myCurrentTime', function($defer, dateFilter) {
181+
// We inject $timeout and dateFilter service since the factory method is DI.
182+
.directive('myCurrentTime', function($timeout, dateFilter) {
183183
// return the directive link function. (compile function not needed)
184184
return function(scope, element, attrs) {
185185
var format, // date format
186-
deferId; // deferId, so that we can cancel the time updates
186+
timeoutId; // timeoutId, so that we can cancel the time updates
187187

188188
// used to update the UI
189189
function updateTime() {
@@ -198,8 +198,8 @@ In this example we will build a directive which displays the current time.
198198

199199
// schedule update in one second
200200
function updateLater() {
201-
// save the deferId for canceling
202-
deferId = $defer(function() {
201+
// save the timeoutId for canceling
202+
timeoutId = $timeout(function() {
203203
updateTime(); // update DOM
204204
updateLater(); // schedule another update
205205
}, 1000);
@@ -208,7 +208,7 @@ In this example we will build a directive which displays the current time.
208208
// listen on DOM destroy (removal) event, and cancel the next UI update
209209
// to prevent updating time ofter the DOM element was removed.
210210
element.bind('$destroy', function() {
211-
$defer.cancel(deferId);
211+
$timeout.cancel(timeoutId);
212212
});
213213

214214
updateLater(); // kick of the UI update process.
@@ -217,7 +217,7 @@ In this example we will build a directive which displays the current time.
217217
</script>
218218
<div ng-controller="Ctrl2">
219219
Date format: <input ng-model='format'> <hr/>
220-
Current time is: <span my-current-time="format"></span
220+
Current time is: <span my-current-time="format"></span>
221221
</div>
222222
</doc:source>
223223
<doc:scenario>

0 commit comments

Comments
 (0)