Data from Child Component to Parent. Best approach?


#1

Hey Guys.

I am trying to implement search feature. Looks something like this.
This is my parent component:

12

Once you click to Advanced it goes to modalController where you can select different filters:
50

I want to filter my search result by those filter by passing object called data.
So. I have an object in my parent component Search.ts
Facebook property should be either 1 or 0 and so on.

 data = {
      search: '',
      facebook: ''
    };

And I want to update facebook property from childComponent once Facebook Allowed is toggled.

I am not sure what is the best way to do it?
Any ideas would be highly appreciated!


#2

:pray:t4::pray:t4::pray:t4:


#3

Are u sure you are in v1? As you have ts file?

If you are in v2 or higher, check the docs on modalcontroller. You need to define a ondismiss handler

Tom


#4

Hey Tom,
You are right, I’m not on v1 :wink: my bad

could you give me an example with ondismiss handler?
it’s a little bit confusing .


#5

Hi

Easy as cake

 presentProfileModal() {
   let profileModal = this.modalCtrl.create(Profile, { userId: 8675309 });
   profileModal.onDidDismiss(data => {
     console.log(data);
   });
   profileModal.present();
 }

Just copy/past example

Otherwise: check the ionic preview app, which showcases all the goodies.

Regards
Tom