Pass data from one component to another


#1

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:


#2

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});


#3

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


#4

Have a look at this.

and this line:

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


#5

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 ? :-/


#6

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:


#7

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…


#8

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


#9

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’)" ;