-
Notifications
You must be signed in to change notification settings - Fork 6.8k
refactor(cdk/menu): use inject
for all injection
#24941
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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)`.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
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
inject
function. This was enabled by angular/angular#45991. This approach has a number of advantages:super
@Optional
injection (null
if not provided) as an optional parameter (undefined
if not provided).I expect this PR to involve some discussion around how we want to approach this in general.