Guest User

Untitled

a guest
Jun 25th, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 KB | None | 0 0
  1. @Directive({
  2. selector: '[carousel]'
  3. })
  4. export class CarouselDirective implements OnInit, OnDestroy {
  5. // ...
  6. timerId: number | null = null;
  7.  
  8. @Input('carouselAutoplay')
  9. set autoplay(autoplay: 'on' | 'off') {
  10. autoplay === 'on' ? this.setAutoplayTimer() : this.clearAutoplayTimer();
  11. }
  12.  
  13. ngOnDestroy() {
  14. this.clearAutoplayTimer();
  15. }
  16.  
  17. private clearAutoplayTimer() {
  18. window.clearInterval(this.timerId);
  19. }
  20.  
  21. private setAutoplayTimer() {
  22. this.timerId = window.setInterval(() => this.next(), 1000);
  23. }
  24. }
Add Comment
Please, Sign In to add comment