Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @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);
- }
- }
Add Comment
Please, Sign In to add comment