According to the Ionic 4 docs, you can pass data via the componentProps property. In Ionic3 I can retrieve it with the navParams Service. How do I do it in Ionic 4?
async presentModal() {
const modal = await this.modalController.create({
component: ModalPage,
componentProps: { value: 123 }
});
return await modal.present();
}
Data can be passed to a new modal through Modal. create() as the second argument. The data can then be accessed from the opened page by injecting NavParams . Note that the page, which opened as a modal, has no special "modal" logic within it, but uses NavParams no differently than a standard page.
Passing data to an Ionic modal This is as simple as calling the componentProps on our modalController create function. number: number = 3; const modal = await this. modalController.
You need to use @Input() decorator.
async presentModal() {
const modal = await this.modalController.create({
component: ModalPage,
componentProps: { value: 123 }
});
return await modal.present();
}
Component:
@Component({
selector: 'ModalPage',
templateUrl: './ModalPage.component.html',
styleUrls: [ './ModalPage.component.css' ]
})
export class ModalPage {
name = 'Angular';
@Input() value: any;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With