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?
31 Answer
Use ActivatedRoute instead of ActivatedRouteSnapshot. Then you can use the snapshot like this:
constructor(activatedRoute: ActivatedRoute) { var snapshot = activatedRoute.snapshot; } 9