0

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!

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Steven
  • 817
  • 1
  • 8
  • 25

1 Answers1

2

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
    });
  }
}
Daniel W Strimpel
  • 8,190
  • 2
  • 28
  • 38