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

Commit

Permalink
fix(docs): Fixed defer to timeout change in timer directive example
Browse files Browse the repository at this point in the history
  • Loading branch information
xrd authored and btford committed Jul 19, 2012
1 parent 17209d5 commit 13b5fd1
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions docs/content/guide/directive.ngdoc
Expand Up @@ -178,12 +178,12 @@ In this example we will build a directive which displays the current time.

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

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

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

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

0 comments on commit 13b5fd1

Please sign in to comment.