Pass data from a form in a modal page to the opener page


#1

Hi all, I just can’t find a Ionic v3 tutorial to know how to pass data from a modal page to its opener page and write results in a Sqlite db.

Sqlite side is already working but I just can’t understand how to use ngForm correctly.

I want to compile my form on the modal page, click submit and write down my data into the db, also logging my result to the console.

Can you suggest some tutorial to follow? Thank you in advance.


#2

I’m not going to go into detail to save data into a SQLLite DB, but I’ll give you an example on how to get data back from a modal.

ParentPage:

let modal =  this.modalCtrl.create(OrdercreateModal);
modal.present();
modal.onDidDismiss((data) =>
{
    console.log(data)
})

ModalPage:
this.viewCtrl.dismiss(data);

So when closing a modal (using dismiss(), you can pass some data).
Using the onDidDismiss callback when creating the modal, you can get the data the modal returns.


#3

Thank you @MattE really. I’m already at the point you explained but I don’t know how to get data from the form.

I don’t understand if I have to use NgForm or FormBuilder or whatever… I can’t catch data from input fields and pass it to “data” var.

If you can give me a hint to get to the point, I’ll be grateful.


#4

I’ve used the formbuilder and get/set values like this

this.loginForm.controls['email'].setValue(this.authProvider.email);
this.loginForm.value.email


#5

Thank you, I did it. :wink: