Created
July 24, 2015 22:16
-
-
Save zacharyblank/93b98718f3623eca9275 to your computer and use it in GitHub Desktop.
Angular Timer Directive
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var timerDirective = function ($interval) | |
{ | |
template: '<div>Seconds Elapsed: {{seconds}}</div>', | |
link: function($scope, element, attrs, controller) { | |
element.on('$destroy', function() { | |
$interval.cancel(controller.timerPromise); | |
}); | |
}, | |
controller: function ($scope){ | |
$scope.seconds = 0; | |
this.timerPromise = $interval(function (){ | |
$scope.seconds++; | |
}, 1000); | |
} | |
} | |
angular.module('myApp', []) | |
.directive('timer', timerdirective) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment