Pass data from one component to another

Hi.

I’m currently making an app based on the sidemenu starter and I can’t find the proper way to pass data from clicking a sidemenu item to the current (single) page view.

Any help would really be appreciated ! :slight_smile:

Are you able to pass the object in as a second paramater when you call setRoot i.e something like:

nav.setRoot(page, {myVal: 1});

Well actually I’m not sure if I can import the NavController inside the app.ts, can I ?

Have a look at this.

and this line:

let nav = this.app.getComponent(‘nav’);

Wow nice ok, thank you, kinda works.
Isn’t that app.getComponent a bit tricky ?

Actually I see that it refreshes the whole view, anyway to bypass that ? :-/

Hmm, not sure about that. I’ve been using this method simply because if I can I tend to follow exactly what the Ionic team do in that Conference app :slight_smile:

Ah ah, of course.

Well actually, I’m using the onPageWillEnter event on that single page that does some init stuff, and first I don’t want it to be executed each time, and secondly this event isn’t even called after the first init since we stay on the same page :-/

Maybe I should try using broadcasting, not sure…

Ok, I’ll use Ionic Events for now, it does the job.

we actually have something called nav.push to route, while routing you can also pass the parameters in as an array or as an object for example i want to route my page to “example.html”

this.nav.push(‘example’,{‘key’:value});

and now in the construction of “example.ts” add some thing like “navParams” and also import the same from angular/core library
now u can fetch the data by just saying " navParams.get(‘key’)" ;