A simple question regarding intervals in RxJS - I have made a carousel where slides change every minute and there is a detail that dissatisfies me. When the slide is switched manually by user to next or previous - interval will still change the slide automatically but in whatever time there's left till interval fires off the new value, so it disregards anything what the user did. How can I make interval know if the user changed the slide, and only from user action count a minute and then change slide automatically. Other times interval should work automatically as regular.
Will be happy to hear ideas, thanks!!!
Here's what I got:
source = interval(10000);
ngOnInit(): void {
this.source.subscribe(() => this.slide('forward'));
}
slide(option): void {
switch (option) {
case 'forward':
this.currentSlide === this.SLIDES.length - 1 ?
this.currentSlide = DEFAULT_SLIDE : this.currentSlide++;
break;
case 'back':
this.currentSlide === DEFAULT_SLIDE ?
this.currentSlide = this.SLIDES.length - 1 : this.currentSlide--;
break;
}
}
Template:
<div class="sliderNav">
<mat-icon (click)="slide('back')">keyboard_arrow_up</mat-icon>
<p>{{currentSlide + 1}}/{{SLIDES.length}}</p>
<mat-icon (click)="slide('forward')">keyboard_arrow_down</mat-icon>
</div>