[英]Pass data to ionic2 menu
I am having a menu whose html i have written in app.html-我有一个菜单,我在 app.html 中编写了其 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.
如何将此数据传递到我的 ionic2 菜单以更新用户名。
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例如:把它放在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]);
});
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.