@@ -178,12 +178,12 @@ In this example we will build a directive which displays the current time.
178
178
179
179
angular.module('time', [])
180
180
// 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) {
183
183
// return the directive link function. (compile function not needed)
184
184
return function(scope, element, attrs) {
185
185
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
187
187
188
188
// used to update the UI
189
189
function updateTime() {
@@ -198,8 +198,8 @@ In this example we will build a directive which displays the current time.
198
198
199
199
// schedule update in one second
200
200
function updateLater() {
201
- // save the deferId for canceling
202
- deferId = $defer (function() {
201
+ // save the timeoutId for canceling
202
+ timeoutId = $timeout (function() {
203
203
updateTime(); // update DOM
204
204
updateLater(); // schedule another update
205
205
}, 1000);
@@ -208,7 +208,7 @@ In this example we will build a directive which displays the current time.
208
208
// listen on DOM destroy (removal) event, and cancel the next UI update
209
209
// to prevent updating time ofter the DOM element was removed.
210
210
element.bind('$destroy', function() {
211
- $defer .cancel(deferId );
211
+ $timeout .cancel(timeoutId );
212
212
});
213
213
214
214
updateLater(); // kick of the UI update process.
@@ -217,7 +217,7 @@ In this example we will build a directive which displays the current time.
217
217
</script>
218
218
<div ng-controller="Ctrl2">
219
219
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>
221
221
</div>
222
222
</doc:source>
223
223
<doc:scenario>
0 commit comments