Created
March 26, 2016 21:14
-
-
Save MacKentoch/d7a968dd7fbda7f19891 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
| import { | |
| Component, | |
| Input, | |
| ViewChild, | |
| AfterViewInit, | |
| OnChanges, | |
| SimpleChange | |
| } from 'angular2/core'; | |
| @Component({ | |
| selector : 'mdl-linear-progress', | |
| template : ` | |
| <div class="mdl-grid"> | |
| <div class="mdl-cell mdl-cell--12-col"> | |
| <div | |
| #ProgBar | |
| class="mdl-progress mdl-js-progress progBarCustom"> | |
| </div> | |
| </div> | |
| </div> | |
| `, | |
| styles : [` | |
| .progBarCustom { | |
| width: 100%; | |
| } | |
| `] | |
| }) | |
| export class MdlLinearProgress implements AfterViewInit, OnChanges { | |
| @Input() currentProgress: number = 0; // by default initial progress to 0% | |
| @ViewChild('ProgBar') ProgBar; // access DOM element by ref : # | |
| private mdlProgressInitDone: boolean = false; // need to wait mdl-componentupgraded event done before using el.MaterialProgress.setProgress | |
| updateProgress() { | |
| this.ProgBar.nativeElement.MaterialProgress.setProgress(this.currentProgress); | |
| } | |
| ngAfterViewInit() { | |
| var self = this; | |
| this.ProgBar.nativeElement.addEventListener('mdl-componentupgraded', function() { | |
| this.MaterialProgress.setProgress(0); | |
| self.mdlProgressInitDone = true; | |
| }); | |
| } | |
| ngOnChanges(changes: {[propName: string]: SimpleChange}) { | |
| if (changes['currentProgress'].currentValue !== changes['currentProgress'].previousValue) { | |
| // to be able to use MaterialProgress.setProgress() be sure mdl-componentupgraded has already triggered!!! | |
| this.mdlProgressInitDone ? this.updateProgress() : false; | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment