Hi Jonas,
I'm not sure I can follow exactly what you are doing, but it seems you want
some kind of eventbus to communicate between some parts of your app that
don't have a direct parent-child relation. Did i get that right?
If so, create a service, and inject it in the places where you need it.
something along those lines:
interface Message {
channel: string;
payload: any;
}
@Injectable()
export class EventBus {
private message$ = new Subject<Message>();
/**
* Push a 'event' into the observable
* @param {channel, payload} Makes sure the Message interface is applied
*/
publish({ channel, payload }: Message): void {
this.message$.next({ channel, payload });
}
/**
* Return an observable that listens to a specific 'channel'
* the observable will contain the payload that is published
* @param channelName -- a string to identify the channel
*/
of(channel: string): Observable<any> {
return this.message$.filter(m => m.channel === channel).map(m => m.payload);
}
}
will take care of most of your issue.
Regards
Sander
--
You received this message because you are subscribed to the Google Groups
"Angular and AngularJS discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.