ionic get data from modal code example
Example 1: ionic modal pass data
...
async presentModal() {
const modal = await this.modalController.create({
component: ModalPage,
componentProps: {
foo: 'hello',
bar: 'world'
}
});
return await modal.present();
}
...
@Component()
export class ModalPage implements OnInit {
foo;
bar;
ngOnInit() {
console.log(`${foo} ${bar}`)
}
}
Example 2: modal controller get data on dismiss
selectUser(user: User):void {
this.modalController.dismiss(user);
}
...
async openUserModal() {
const modal = await this.modalCtrl.create({
component: UserModalComponent,
componentProps: { users: this.users },
});
modal.onDidDismiss()
.then((data) => {
const user = data['data'];
});
return await modal.present();
}