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();
Thanks for the update. I actually see the issue. Your code must be publishing to the topic first and letter subscribing while the original publisher might have removed by that time.
If you look closely, I have already left two comments in the code to either use
ReplySubject
(for scenario 1) orOr you can create a new subject for future subscribers
(for another scenario).Now, again based on the actual clarity of your requirement, you either have to change the code accordingly. Let me know if you need to fix and use it.