Search code examples
javascriptangularsiema

ngx-siema how to set interval


I am trying to mimic an autoplay setting for ngx-siema , using:

setInterval(() => mySiema.next(), 1000)

as described here.

How can I do that? Here is my setup:

export class SliderComponent implements OnInit {
    constructor(private ngxSiemaService: NgxSiemaService) {}

    ngOnInit() {}

    options: NgxSiemaOptions = {
        selector: ".siema",
        duration: 1000,
        loop: true
    };
}

Solution

  • So, using the provided service (which provides the init function), I added a next() method with a desired setInterval, as follows:

    export class SliderComponent implements OnInit {
        constructor(private ngxSiemaService: NgxSiemaService) {}
    
        ngOnInit() {
            this.next();
        }
    
        options: NgxSiemaOptions = {
            selector: ".siema",
            duration: 1000,
            loop: true
        };
    
        next() {
            setInterval(() => {
                this.ngxSiemaService.next(1);
            }, 3000);
        }
    }