refactor(cdk/menu): use inject for all injection#24941
Conversation
inject for all injection
inject for all injectioninject for all injection
0342974 to
7403ce8
Compare
src/cdk/menu/menu-trigger-base.ts
Outdated
| protected readonly viewContainerRef = inject(ViewContainerRef); | ||
|
|
||
| /** The menu stack in which this menu resides. */ | ||
| protected readonly menuStack: MenuStack | null = inject(MENU_STACK, InjectFlags.Optional); |
There was a problem hiding this comment.
Why is this optional now? It used to be required. It causes some extra null checks in the components extending this one.
There was a problem hiding this comment.
Bad copy and paste, removed the optional
3a49f30 to
dc200d7
Compare
|
CI failures are resolved. I had to disable the no bitwise operator lint since it's required for this API |
|
Made another update to remove some unnecessary explicit types. e.g., if you have class MenuTrigger {
menuAim = inject(MENU_AIM, InjectFlags.Optional);
}it will automatically infer |
|
Looks like still some lint & api failures |
|
Whoops, I had it green and then messed up the formatting when I made that last edit. Fixed. |
This change switches the cdk menu from using constructor injection to using the `inject` function. This was enabled by angular/angular#45991. This approach has a number of advantages: * We can add and remove injectables without changing the public constructor signature * It reduces the boilerplate of passing arguments through `super` * It avoids long/messy constructor blocks in favor of simpler member definitions. * This sidesteps a common pitfall of making `@Optional` injection (`null` if not provided) as an optional parameter (`undefined` if not provided)`.
This change switches the cdk menu from using constructor injection to using the `inject` function. This was enabled by angular/angular#45991. This approach has a number of advantages: * We can add and remove injectables without changing the public constructor signature * It reduces the boilerplate of passing arguments through `super` * It avoids long/messy constructor blocks in favor of simpler member definitions. * This sidesteps a common pitfall of making `@Optional` injection (`null` if not provided) as an optional parameter (`undefined` if not provided)`.
|
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
This change switches the cdk menu from using constructor injection to using the
injectfunction. This was enabled by angular/angular#45991. This approach has a number of advantages:super@Optionalinjection (nullif not provided) as an optional parameter (undefinedif not provided).I expect this PR to involve some discussion around how we want to approach this in general.