Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ionic 4 - how to retrieve data passed to a modal

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();
  }
like image 907
Han Che Avatar asked Aug 24 '18 22:08

Han Che


People also ask

How do you get data from modal in Ionic?

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.

How do you pass data to modal Ionic 4?

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.


1 Answers

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;
}
like image 180
Suresh Kumar Ariya Avatar answered Oct 19 '22 03:10

Suresh Kumar Ariya