Unable to inject ActivatedRouteSnapshot

Injecting ActivatedRouteSnapshot into a component is not working (and neither is injecting ActivatedRoute). Here the stack trace:

"Error: Can't resolve all parameters for ActivatedRouteSnapshot: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?). at SyntaxError.ZoneAwareError () at SyntaxError.BaseError [as constructor] () at new SyntaxError () at CompileMetadataResolver._getDependenciesMetadata () at CompileMetadataResolver._getTypeMetadata () at CompileMetadataResolver._getInjectableMetadata () at CompileMetadataResolver.getProviderMetadata () at at Array.forEach (native) at CompileMetadataResolver._getProvidersMetadata () at CompileMetadataResolver.getNonNormalizedDirectiveMetadata () at CompileMetadataResolver._loadDirectiveMetadata () at at Array.forEach (native) at CompileMetadataResolver.loadNgModuleDirectiveAndPipeMetadata ()" 

In the component, ActivatedRouteSnapshot is injected as follows:

constructor([...], private router: Router, private route: ActivatedRouteSnapshot) { [...] } 

ActivatedRouteSnapshot is provided in app.component.ts:

@Component({ selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.css'], providers: [[...], ActivatedRouteSnapshot] }) 

I'm trying to access the query params similarly to how it is done here:

According to the docs it should be as simple as adding it to the constructor parameters:

What am I missing to successfully inject ActivatedRouteSnapshot?

3

1 Answer

Use ActivatedRoute instead of ActivatedRouteSnapshot. Then you can use the snapshot like this:

constructor(activatedRoute: ActivatedRoute) { var snapshot = activatedRoute.snapshot; } 
9

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like