Skip to content

Instantly share code, notes, and snippets.

@Ademking
Created July 1, 2019 05:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ademking/b850934dd52c72f35c50d68d0e8830d1 to your computer and use it in GitHub Desktop.
Save Ademking/b850934dd52c72f35c50d68d0e8830d1 to your computer and use it in GitHub Desktop.
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