Last active
June 24, 2018 15:25
-
-
Save realtomaszkula/43e0b15ef13df8eca2ceda029b44074f 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
| @Directive({ | |
| selector: '[carousel]' | |
| }) | |
| export class CarouselDirective implements OnInit, OnDestroy { | |
| // ... | |
| timerId: number | null = null; | |
| @Input('carouselAutoplay') | |
| set autoplay(autoplay: 'on' | 'off') { | |
| autoplay === 'on' ? this.setAutoplayTimer() : this.clearAutoplayTimer(); | |
| } | |
| ngOnDestroy() { | |
| this.clearAutoplayTimer(); | |
| } | |
| private clearAutoplayTimer() { | |
| window.clearInterval(this.timerId); | |
| } | |
| private setAutoplayTimer() { | |
| this.timerId = window.setInterval(() => this.next(), 1000); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment