Created
July 13, 2016 10:43
-
-
Save jordic/c0116955cb3f2d752cdbc70ed39a4436 to your computer and use it in GitHub Desktop.
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
| (function(){ | |
| angular.module('mnt') | |
| .directive('tTimer', function() { | |
| return { | |
| template: [ | |
| '<div class="tpreload">', | |
| ' <div style="width:{{$ctrl.percent}}%"></div>', | |
| '</div>' | |
| ].join("\n"), | |
| scope: { | |
| duration: '@', | |
| callback: '&' | |
| }, | |
| controller: tTimerCtrl, | |
| controllerAs: '$ctrl', | |
| bindToController: true | |
| }; | |
| }); | |
| /** @ngInject */ | |
| function tTimerCtrl($log, $timeout, $scope, $interval) { | |
| var vm = this; | |
| //$log.log("Ttimer: ", this.duration); | |
| //$log.log(this.callback); | |
| var time = parseInt(this.duration); | |
| var t = $timeout(function(){ | |
| vm.callback(); | |
| }, time); | |
| var start = new Date().getTime(); | |
| function elapsed() { | |
| return (new Date().getTime() - start) | |
| } | |
| var inter = $interval(function(){ | |
| vm.percent = (elapsed()/time) * 100 | |
| //$log.log(vm.percent); | |
| }, 10); | |
| $scope.$on("$destroy", function(){ | |
| $log.log("Directive destroyed.."); | |
| $timeout.cancel(t); | |
| $interval.cancel(inter); | |
| }); | |
| } | |
| })(); |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Per inicialitzar-la: