Yes you can achieve this using rxjs
with BehaviourSubject
You have to put some value in checkbox and then onchange
you have to call a function which notifies the subscriber in your another component. I am writing up a very basic example for you.
In your sender.component.html
you can do like this
<input type=checkbox [(ngModel)]="myCheckBox" (ngChanged)="!myCheckBox" (change)="notifyOtherComponent()">
Then in your service.ts
you can do like this
import { BehaviorSubject } from 'rxjs';
private messageSource = new BehaviorSubject('default message');
public currentMessageSubscriber = this.messageSource.asObservable();
notify(message: any) {
this.messageSource.next(message)
}
And in your sender.component.ts
you can do like this
constructor(private __dataService : DataService){}
notifyOtherComponent(){
this.__dataService.notify({msg : 'do something'})
}
And in your listener.component.ts you can subscribe to BehaviourSubject
type Observable
to listen the latest value like this
constructor(private __dataService : DataService){}
ngOnInit() {
this.__dataService.currentMessageSubscriber.subscribe((data : any)=>{
console.log(data) // output : {msg : 'do something'}
})
}
In this way you will be sending data to observable from one component and listening that data into another component.