fix(docs): Fixed defer to timeout change in timer directive example

This commit is contained in:
Chris Dawson 2012-06-19 15:38:02 -04:00 committed by Brian Ford
parent 17209d5b4a
commit 13b5fd1b9d

View file

@ -178,12 +178,12 @@ In this example we will build a directive which displays the current time.
angular.module('time', []) angular.module('time', [])
// Register the 'myCurrentTime' directive factory method. // Register the 'myCurrentTime' directive factory method.
// We inject $defer and dateFilter service since the factory method is DI. // We inject $timeout and dateFilter service since the factory method is DI.
.directive('myCurrentTime', function($defer, dateFilter) { .directive('myCurrentTime', function($timeout, dateFilter) {
// return the directive link function. (compile function not needed) // return the directive link function. (compile function not needed)
return function(scope, element, attrs) { return function(scope, element, attrs) {
var format, // date format 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 // used to update the UI
function updateTime() { function updateTime() {
@ -198,8 +198,8 @@ In this example we will build a directive which displays the current time.
// schedule update in one second // schedule update in one second
function updateLater() { function updateLater() {
// save the deferId for canceling // save the timeoutId for canceling
deferId = $defer(function() { timeoutId = $timeout(function() {
updateTime(); // update DOM updateTime(); // update DOM
updateLater(); // schedule another update updateLater(); // schedule another update
}, 1000); }, 1000);
@ -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 // listen on DOM destroy (removal) event, and cancel the next UI update
// to prevent updating time ofter the DOM element was removed. // to prevent updating time ofter the DOM element was removed.
element.bind('$destroy', function() { element.bind('$destroy', function() {
$defer.cancel(deferId); $timeout.cancel(timeoutId);
}); });
updateLater(); // kick of the UI update process. updateLater(); // kick of the UI update process.
@ -217,7 +217,7 @@ In this example we will build a directive which displays the current time.
</script> </script>
<div ng-controller="Ctrl2"> <div ng-controller="Ctrl2">
Date format: <input ng-model='format'> <hr/> 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> </div>
</doc:source> </doc:source>
<doc:scenario> <doc:scenario>