This is a sharing service called dShareService:
@Injectable()
export class DInfoShareService {
constructor() { }
// Observable sources
private dInfo = new Subject<DInfo>();
dInfo$ = this.dInfo.asObservable();
// Service message commands
public SetDInfo(dinfo: DInfo) {
this.dInfo.next(dinfo);
}
}
This is the parent component:
Within the parent component, there is a button click event that triggers a method which passes data to a service.
GoToDetail(value){
this.dShareService.SetDInfo(value);
// This is a child component and is accessed via a route. Typically, I would use the current state and pass data to the child
// component. However, in this scenario, there are 3 tab pages on the UI and each page requires this data.
this.router.navigateByUrl('/dchild', {
state: {dInfo: value}
});
This is the child component:
Within the constructor,
this.dinfoShareService.dInfo$.subscribe(res=>
{
//This part never gets executed
this.dInfo = res;
}
);
The subscription within the child component is not triggering. Can anyone help me identify what I am doing wrong?