Skip to content

Instantly share code, notes, and snippets.

@Ademking Ademking/README.md
Created Jul 1, 2019

Embed
What would you like to do?
Events in Ionic 4

from https://stackoverflow.com/questions/45211533/ionic-3-refresh-side-menu-after-login

Refresh sidemenu using Events

import { Events } from 'ionic-angular';

// login.ts page (publish an event when a user is created)
constructor(public events: Events) {}
createUser(user) {
  console.log('User created!')
  this.events.publish('user:created', user, Date.now());
}


// app.component.ts page (listen for the user created event after function is called)
constructor(public events: Events) {
  events.subscribe('user:created', (user, time) => {
    // user and time are the same arguments passed in `events.publish(user, time)`
    console.log('Welcome', user, 'at', time);
  });
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.