// In the service
export class simpleService{
private subject = new Subject<any>();
constructor() { }
// Service message commands
// Read Service Data
onReadData(data: any){
this.subject.next(data);
}
// Send Service Data
onSendData() {
return this.subject.asObservable();
}
}
// In the component you want to send the data to
dataSubscription: Subscription;
constructor(private simpleService: SimpleService){
this.dataSubscription = this.simpleService.onSendData().subscribe( async (data) => {
// do whaterver you want with the incoming data
console.log('incoming data: ', data);
});
}