johnny 5
johnny 5

Reputation: 20995

Angular Pass Input to Ionic Modal

I have a component which takes in an Input parameter:

export class MapComponent implements OnInit {
   @Input() options: MapOptions<any>;
}

I page which opens this modal using the ionic ModalController:

async pickLocationModal() {
  const modal = await this.modalController.create({
    component: MapComponent
  });
  return await modal.present();
}

Additionally I have mapOptions stored in the page, which I would like to pass.

I can I pass my mapOptions to the Modal so the component will take it as an input?

Upvotes: 1

Views: 563

Answers (1)

Eliya Cohen
Eliya Cohen

Reputation: 11478

I'm assuming you're using Ionic since this is the same implementation of ionic's ModalController.

According to their docs, it's possible by passing to componentProps:

async pickLocationModal() {
  const modal = await this.modalController.create({
    component: MapComponent,
    componentProps: { // <----------
      options: ...
    }
  });
  return await modal.present();
}

Upvotes: 4

Related Questions