I have a lazy-loaded route with resolver:
const routes: Routes = [
{
path: '',
children: [
{
path: '',
component: MyComponent,
resolve: {
data: MyService
}
}
]
}
];
@NgModule({
imports: [RouterModule.forChild(routes)],
exports: [RouterModule]
})
export class MyRoutingModule {}
My module
@NgModule({
imports: [
CommonModule,
MyRoutingModule,
...
],
declarations: [
MyComponent,
...
],
providers: [MyService]
})
export class MyModule {}
My service resolver:
resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<any> {
return forkJoin(
this.getData1(),
this.getData2(),
this.getData3()
);
}
I am subscribing to the property data on my app component:
export class AppComponent implements OnInit {
constructor(private route: ActivatedRoute) {}
ngOnInit() {
this.route.data.subscribe(x => {
data = x; //x = undefined
});
}
}
The problems is x is always undefined
Any ideas why I can not access to my resolved data and how to fix that ?
UPDATE: I want to know when data resolved so I want to hide the spinner. As per @OneLunch-Man post my app component won't have an access to that data, so how would you work that out, all I need to know on my app component is when data has being resolved so I can do some UI state changes like hiding a spinner, etc