I tried using console.log in both the constructor and ngOnInit() of Resolver but for some reason, they are not being logged.
resolve:{serverResolver:ServerResolverDynamicDataService}},
console.log("ServerResolverDynamicDataService constructor");
console.log('ServerResolverDynamicDataService resolve:'
const appRoutes : Routes =[
{path:"",component:HomeComponent},
{path:"servers",canActivateChild:[AuthGuardService],component:ServersComponent,
children:[
{path:":id",component:ServerComponent,
resolve:{serverResolver:ServerResolverDynamicDataService}},
{path:":id/edit",component:EditServerComponent,canDeactivate:[CanDeativateGuardService]}]},
Resolver:
@Injectable()
export class ServerResolverDynamicDataService implements Resolve<ServerModel>{
constructor(private serversService:ServersService){
console.log("ServerResolverDynamicDataService constructor");
}
resolve(activatedRouteSnapshot: ActivatedRouteSnapshot, routerStateSnapshot:
RouterStateSnapshot): ServerModel | Observable<ServerModel> | Promise<ServerModel> {
console.log('ServerResolverDynamicDataService resolve:'+activatedRouteSnapshot.params['id']);
return this.serversService.getServer(+activatedRouteSnapshot.params['id']);
}
}
Update1: The service is properly registered in the providers array of app.module.ts
providers: [ServersService,AuthGuardService,AuthService,CanDeativateGuardService,ServerResolverDynamicDataService],
Even though the resolver code contains log statements, they do not appear in the console when hitting a specific URL like http://localhost:4200/servers/1?allowToEdit=0&allowTest=2#loadPage. Strangely, changes made elsewhere in the application reflect successfully, indicating that the application refreshes as expected except for the resolver function.
Update2 A StackOverflow post suggests removing the parent canActivateChild service to make it work, but I am unsure about what exactly is causing the issue. Any help in understanding this discrepancy would be greatly appreciated.