Which @angular/* package(s) are the source of the bug?
router
Is this a regression?
No
Description
There is the NullInjectorError if we try to use the CanMatch guard that is provided at the route level:
export class Guard implements CanMatch {
canMatch(): boolean {
return true;
}
}
export const appRoutes: Route[] = [
{
path: 'foo',
component: FooComponent,
// error
canMatch: [Guard],
providers: [Guard],
},
];
If we try to use e.g. CanActivate guard that is provided at the route level, it will be properly injected:
export const appRoutes: Route[] = [
{
path: 'foo',
component: FooComponent,
// works
canActivate: [Guard],
providers: [Guard],
},
];
Please provide a link to a minimal reproduction of the bug
No response
Please provide the exception or error you saw
ERROR Error: Uncaught (in promise): NullInjectorError: R3InjectorError(AppModule)[Guard -> Guard -> Guard]:
NullInjectorError: No provider for Guard!
NullInjectorError: R3InjectorError(AppModule)[Guard -> Guard -> Guard]:
NullInjectorError: No provider for Guard!
at NullInjector.get (core.mjs:9091:27)
at R3Injector.get (core.mjs:9258:33)
at R3Injector.get (core.mjs:9258:33)
at R3Injector.get (core.mjs:9258:33)
at NgModuleRef.get (core.mjs:22413:33)
at router.mjs:3313:32
at Array.map (<anonymous>)
at runCanMatchGuards (router.mjs:3312:42)
at matchWithChecks (router.mjs:3340:12)
at ApplyRedirects.matchSegmentAgainstRoute (router.mjs:3674:16)
at resolvePromise (zone.js:1211:31)
at resolvePromise (zone.js:1165:17)
at zone.js:1278:17
at _ZoneDelegate.invokeTask (zone.js:406:31)
at Object.onInvokeTask (core.mjs:26501:33)
at _ZoneDelegate.invokeTask (zone.js:405:60)
at Zone.runTask (zone.js:178:47)
at drainMicroTaskQueue (zone.js:585:35)
at ZoneTask.invokeTask [as invoke] (zone.js:491:21)
at invokeTask (zone.js:1648:18)
Please provide the environment you discovered this bug in (run ng version)
Angular CLI: 14.0.1
Node: 14.17.1
Package Manager: yarn 1.22.17
OS: win32 x64
Angular: 14.0.1
... animations, cli, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic
Package Version
---------------------------------------------------------
@angular-devkit/architect 0.1400.1
@angular-devkit/build-angular 14.0.1
@angular-devkit/core 14.0.1
@angular-devkit/schematics 14.0.1
@angular/router 14.1.0-next.1+sha-df1652e
@schematics/angular 14.0.1
rxjs 7.5.5
typescript 4.6.4
Anything else?
No response
Which @angular/* package(s) are the source of the bug?
router
Is this a regression?
No
Description
There is the
NullInjectorErrorif we try to use theCanMatchguard that is provided at the route level:If we try to use e.g.
CanActivateguard that is provided at the route level, it will be properly injected:Please provide a link to a minimal reproduction of the bug
No response
Please provide the exception or error you saw
Please provide the environment you discovered this bug in (run
ng version)Anything else?
No response