Get current page name in event listener


I want to get current page name in event listener.
Please see the following codes.

export class TabsPage {
      constructor(...) {
      this.mail.getPostEvent().subscribe(post => {
          let currentPageName = this.navCtrl.getActive().name;

post event occurs anytime.
this.navCtrl.getActive().name doesn’t return current page name.
Do you have any idea?
Please give me some advice.


Don’t do this. It will break under minification, and is bad design anyway, because it encourages spaghetti control structure. If you describe what you are really trying to achieve in broader terms, maybe we can help suggest alternatives.


I implement real-time chat using pusher js.
Btw I want to notify user that new mesage arrived when user are not on chat room.
How can I do this?


Maybe local notifications would work?


I use local notification native plugin to notify user. But it happens every time when new message arrives even though user does see it. so I want to know if user is on chat room or not.


The way I think about programming, “me the programmer” doesn’t exist. “Me the ChatPage” does, and so if you want to handle notifications differently when it’s the current page, I would suggest using lifecycle events to register and unregister listeners that control that behavior. That way all the ChatPage stuff stays in the ChatPage, instead of getting diffused throughout the app.