I want to pass the data from one component to another component using Subject. I am using Angular 7. Below is my service: -
public shareData = new Subject();
setShareDataOfReadingDetail(datatobeShared:any){
console.log(datatobeShared)
this.shareData.next(datatobeShared);
this.shareData.complete()
}
getShareDataOfReadingDetail(){
return this.shareData.asObservable();
}
My first component is : -
shareDetail(detail){
this.readingService.setShareDataOfReadingDetail(detail)
this.router.navigate(['./tabs/tabs/readings/detail'])
}
And the component in which I am getting the data is : -
ngOnInit() {
this.readingService.getShareDataOfReadingDetail().subscribe((data)=>{console.log(data)})
}
But the subscribe for subject is not triggering at all (i.e it is not printing anything in the console)