import {Events} from 'ionic-angular';
import {Events} from '../your/path/to/service/events';
events.subscribe('user:created', (user, time) => {
console.log('Welcome', user, 'at', time);
});
this.events.subscribe('user:created', (data: any) => {
console.log('Welcome', data.user, 'at', data.time);
});
this.events.publish('user:created', someUserInstance, Date.now());
this.events.publish('foo:user:logged-out', {
user: someUserInstance,
time: new Date()
});
const subscription = this.events.subscribe('user:foo:created', (data: any) => {
// your logic
});
Once you are done, you can do this-
subscription.unsubscribe();
@sagrawal31 I have reached a roadblock with this. It works great with a component/page and a modal. However, it does not work at all between the component to component or page to page.
Is this correct? Or is this meant to work between components as well? I have a list of items, I click on the item to navigate t its detailed page/component. I perform an action like delete or archive which I intended to use events to emit back to the list in order to splice it from the array and remove it from view.
In standard Angular, I would just have the parent component and the child component emitting an event to the parent component in order to pass this communication. I understand that Ionic does work a tad differently in some areas.