I have a route configuration which allows a user to view the recent activities that has been done based on a criteria like so :
{ path: 'workspace', component: WorkspaceComponent, children: [
{ path: 'upload', component: UploadComponent },
{ path: 'verify', component: VerifyComponent, resolve:{dataObject: RecentActivityResolver}}]}
The resolver returns a object from an arraylist stored in a service class. I am not directly accessing the service class in my VerifyComponent since I intend to change from arrays to HTTP requests soon.
@Injectable()
export class RecentActivityResolver implements Resolve<RecentActivityModel>{
constructor(private recentActivity: RecentActivityService){}
resolve(activatedRoute: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<RecentActivityModel> |
Promise<RecentActivityModel> | RecentActivityModel {
console.log(activatedRoute.queryParams['id']); // gives me the correct result here
return this.recentActivity.recentActivities[+activatedRoute.queryParams['id']];
}
}
On my child component I fetch the details from the data observable like so :
ngOnInit(){
this.activatedRoute.data.subscribe((data: Data) => {
console.log(data['dataObject']); // undefined
this.displayActivity = data['dataObject'];
});
this.activatedRoute.queryParams.subscribe((data: Data) =>{
console.log(data['id']); // correct data here
});
}
I am not able to understand why the data is not coming here. Can anyone guide me? Thanks in advance.