Skip to content

Instantly share code, notes, and snippets.

@zacharyblank
Created July 24, 2015 22:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zacharyblank/93b98718f3623eca9275 to your computer and use it in GitHub Desktop.
Save zacharyblank/93b98718f3623eca9275 to your computer and use it in GitHub Desktop.
Angular Timer Directive
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