I have a component 'panel' which is having two child routes dashboard and holidays. Both these child routes are getting a data on their ngOnInit from parent component service.
Everything is working fine and dashboard is loading with data if we are going in normal way, but if we are reloading the child route its not getting the parent service data.
How to solve this issue?
Routing module:-
{
path: 'panel',
component: PanelComponent,
canActivate: [AuthGuard],
children: [
{
path: 'dashboard',
component: DashboardComponent,
},
{
path: 'holidays',
component: HolidaysComponent
}
]
}
panelComponent.ts:-
export class PanelComponent implements OnInit {
constructor(private panelService: PanelService, route: ActivatedRoute, private router: Router) {
}
ngOnInit() {
this.panelService.getUserProfile().subscribe(
res => {
this.panelService.userDetails = res;
this.router.navigate(['panel/dashboard'])
},
err => {
console.log(err);
},
);
}
DashboardComponent.ts:-
export class DashboardComponent {
/** dashboard ctor */
private userDetails = {
name:""
}
constructor(private panelService: PanelService) {
}
ngOnInit() {
//console.log(this.panelService.userDetails.profileDetails[0].name);
this.userDetails.name=this.panelService.userDetails.profileDetails[0].name
}