Ionic 2:事件发布/订阅无效

时间:2017-07-10 05:39:38

标签: ionic2

用户登录后,他们的登录信息将设置为本地存储,并转发到DashboardPage。   我想要做的就是一旦用户登录并将用户转发到仪表板我想用登录用户详细信息更新滑动菜单。

在Dashboard页面的构造函数中,我发布了这样的事件 -

 let userinfo = this.storagehelper.getStorageItem("userinfo");
  this.event.publish("app:userLoggedIn", userinfo);

app.component.ts中,我订阅了这样的事件 -

 this.event.subscribe("app:userLoggedIn", userObject => {
       console.warn("Listening to published event");
       this.setMenuUsers(userObject);
  });

  setMenuUsers(userinfo){
      this.LoginUserEmail = userinfo.UserName;
      this.LoginUserName = userinfo.EmployeeName;
      this.LoginUserCompany = userinfo.CompanyName;
  }

问题

菜单没有更新,订阅活动根本不起作用。任何人都可以帮助我做错了吗?

1 个答案:

答案 0 :(得分:1)

试试这种方式 - TS:

async saveUser () {
  let userinfo = await this.storagehelper.getStorageItem("userinfo");
  this.event.publish("app:userLoggedIn", userinfo);
}
相关问题