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();
Hi @johnwargo, updated the documentation for you which now shows how to unsubscribe once you are done.
@vahidvdn yes that is possible. May I know which syntax you are looking for?
subscribe
,publish
or both?