Reputation: 655
I am having a menu whose html i have written in app.html-
<ion-menu [content]="mycontent">
<ion-toolbar class = "menuUserName">
<ion-title>{{userName}}</ion-title>
</ion-toolbar>
<ion-content>
<ion-list>
...
</ion-list>
</ion-content>
</ion-menu>
<ion-nav #mycontent [root]="rootPage"></ion-nav>
My app flow is login->homepage. when the user login the app,it will get username from a service. How can i pass this data to my ionic2 menu to update username.
Upvotes: 2
Views: 2104
Reputation: 2478
Your problem is passing data between pages. I think you should use Ionic Events
for sending and responding to application-level events across your app.
For example: put it in app.ts
function createUser(user) {
console.log('User created!')
events.publish('user:created', user);
}
function listenToLoginEvents(){
events.subscribe('user:created', (userEventData) => {
console.log('Welcome', userEventData[0]);
});
}
Upvotes: 2