Benjamin_Zaufall
Benjamin_Zaufall

Reputation: 1

Angular/Ionic listen to Ionic-Event

We have an Ionic-Angular Frontend Application with following Problem:

There is this component:

...

export class StepIndicatorComponent {
  @Input() slides: IonSlides;

...

}

Now i want to add an event listener to slides for the event "ionSlideDidChange". Everytime the event gets triggered, a method should be called.

I tried rxjs, Hostlistener, but theses are only for DOM objects.

I know i can can add the methodcall for the event in the html, but in this case i have to do it in the .ts component file.

Any ideas?

Thx


Ion Slides API: https://ionicframework.com/docs/api/slides

Upvotes: 0

Views: 828

Answers (1)

Jiri Kralovec
Jiri Kralovec

Reputation: 1617

IonSlides is an element, you can't use @Input declaration. You can simply bind the event on the element itself

<ion-slides (ionSlideDidChange)="onSlideChange($event)">
  <ion-slide>
    <h1>Slide 1</h1>
  </ion-slide>
</ion-slides>

See the example here : https://stackblitz.com/edit/ionic-g3sehf

Upvotes: 1

Related Questions