Marco24690
Marco24690

Reputation: 355

Angular is it possible to access resolved data within route definition?

I need to do some stuff within the route definition, when the lazyloaded module is loaded. The route has a resolver UserDataResolverService, how can I access the resolved data within the route definition?

 {
        path: 'path-a',
        resolve: { userData: UserDataResolverService},
        loadChildren: () =>
            import('./pages/my.module').then((m) => {
                // access resolved data here: userdata.details
                return m.MyModule;
            }),
  }

Upvotes: 0

Views: 159

Answers (1)

Fabian Strathaus
Fabian Strathaus

Reputation: 3570

You can simply inject ActivatedRoute in your child component and then use

constructor(private route: ActivatedRoute) {
    console.log(this.route.snapshot.data['userData']);
}

Upvotes: 1

Related Questions