0

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

enter image description here

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

enter image description here

I want to filter my search result by those filter by passing object called data. Facebook property should be either 1 or 0 and so on.

So for example one toggle is on, set data = { facebook = '1'}

So. I have an object in my parent component Search.ts

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!

dar3l
  • 55
  • 1
  • 8
  • https://stackoverflow.com/questions/31026886/how-do-i-share-data-between-components-in-angular-2 – AT82 Oct 26 '17 at 12:34

1 Answers1

0

When you close modal at that time you pass data to child component like

this.viewCtrl.dismiss(this.pick_color);

Instead of this.pick_color you have pass your object of facebook and email allowed.

You have to catch passed value in child component like

let colorModal = this.modalCtrl.create(ColorModal, { notes_data_id: notes_data_id });
colorModal.present();

colorModal.onDidDismiss(data=>
{
    console.log(data);   
});

For more info

https://forum.ionicframework.com/t/passing-data-in-from-modal/61051/2

Paresh Gami
  • 4,777
  • 5
  • 23
  • 41
  • Super. Did that. Now I receive the object from child component to parent. After console.log(data) I receive: {facebook: "1", email: ""} Question is : How can I now insert this data to my data object in parent component. Rookie out here! Thanks – dar3l Oct 26 '17 at 12:58
  • Now I receive the object from child component to parent. After console.log(data) I receive: {facebook: "1", email: ""} Question is : How can I now insert this data to my data object in parent component. Rookie out here! Thanks – dar3l Oct 26 '17 at 13:00
  • You can use that object in your child component. – Paresh Gami Oct 26 '17 at 13:02
  • yeah, but the thing is. I use data object in parent component to send it to the API and by object parameters, it's got the data. So I need somehow to pass facebook parameter value from child component to parent data object. Not sure if it makes sense for you. – dar3l Oct 26 '17 at 13:06
  • You mean facebook allowed, email allowed also dynamic mean they comes from api call? – Paresh Gami Oct 26 '17 at 13:08
  • No, but I have to pass them as parameter to the api if I user want to see list where facebook or email is allowed. – dar3l Oct 26 '17 at 13:11
  • Means when onDidDismiss() is called you have to pass facebook and email object to with api call right? – Paresh Gami Oct 26 '17 at 13:12
  • Yes. I pass data variable to api from my Search.ts (parent component) data = { category: ' ', search: ' ', facebook: ' ', email: ' ' }; – dar3l Oct 26 '17 at 13:15
  • For that you have use event and publish – Paresh Gami Oct 26 '17 at 13:18
  • Thanks! Could you help me with where should i start? – dar3l Oct 26 '17 at 13:34
  • Please refer given link for events and publish for ionic 3. If i helps you please dont forgot accept and upvote to answer – Paresh Gami Oct 26 '17 at 13:36