I have two components A and B, and when an event occurs in A, I need to get the updated value in B in which I am subscribing to a service to get the latest value from A.
component A:
sendString(inputEntered){ //happens when on buttonclick
....
this.myService.sendRecent(inputEntered);
}
Service:
export class myService {
private inputStringSource = new Subject<string>();
public inputString$ = this.inputStringSource.asObservable();
constructor() {}
sendRecent(inputString: string) {
this.inputStringSource.next(inputString);
}
component B:
...
ngOnInit(): void {
this.myService.inputString$.subscribe(data => {
console.log("input value ", data);
});
Service is receiving new value but the subscription in component B is not being triggered.. what am I doing wrong here? Please let me know. Tried few option but still no luck.