angularsiema

Using Siema's api with Angular's onclick


I want to use Angular's onclick and inside use Siema's api to go the next slide. The problem is that I have no choice but to initialize the slider inside ngAfterViewInit. Anyway I can have access to the api outside of that function? I want to avoid querying a html selector and try to use a real angular click for this.

https://stackblitz.com/edit/angular-ctflzc

export class AppComponent  {
  name = 'Angular';

  siema = Siema;

  changeSlide() {
    this.siema.next();
  }

    ngAfterViewInit(): void {
    new Siema({
      loop: true
    });
  }
}

This is what I tried, but it does not seem to work.

Any help is appreciated!


Solution

  • As mentioned in the comment, you just need to hold onto the reference of the carousel you are creating in your code:

    export class AppComponent  {
      siema: Siema;
    
      changeSlide() {
        this.siema.next();
      }
    
      ngAfterViewInit(): void {
        this.siema = new Siema({
          loop: true
        });
      }
    }