You can use the general service for this.
export class EventSourceComponent{ constructor(private sharedService : SharedService){} onbtnclick(){ this.sharedService.testev.next("i have emitted an event") } } export class CmpTwoComponent{
and then sharedService will be
@Injectable() export class SharedService{ public testev = new Subject() }
Obviously, if you still need Output so that the parent component can subscribe normally, you can also add this:
export class EventSourceComponent{ @Output() testev = new EventEmitter(); constructor(private sharedService : SharedService){} onbtnclick(){ this.testev.emit("i have emitted an event") this.sharedService.testev.next("i have emitted an event") } }
Milad source share