Quantcast
Channel: Ionic Forum - Latest topics
Viewing all articles
Browse latest Browse all 70440

Getting data from Modal Controller

$
0
0

@sj9 wrote:

Hello
for getting data in opened modal in official documentation was written this example

async presentModal() {
  const modal = await this.modalController.create({
    component: ModalPage,
    componentProps: {
      'firstName': 'Douglas',
      'lastName': 'Adams',
      'middleInitial': 'N'
    }
  });
  return await modal.present();
}

To get the data passed into the componentProps, either set it as an @Input or access it via NavParams on the ModalPage:

export class ModalPage {

  // Data passed in by componentProps
  @Input() firstName: string;
  @Input() lastName: string;
  @Input() middleInitial: string;

  constructor(navParams: NavParams) {
    // componentProps can also be accessed at construction time using NavParams
    console.log(navParams.get('firstName'));
  }

}


BUT

I also can get data like this —

async presentModal() {
  const modal = await this.modalController.create({
    component: ModalPage,
    componentProps: {
      firstName: 'Douglas',
     
    }
  });
  return await modal.present();
}


and for getting data in Modal,   for example, the value of - firstName,   
  I can do it in ngOnInit    life hook

export class ModalPage {

public firstName : string
  constructor( ) {
      
  }
ngOnInit(){
console.log(this.firstName)  // output will be -  'Douglas'
}
}

So I want to know is this an error? or it is normal behavior for the modal controller???

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 70440

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>