Skip to content

refactor(cdk/menu): switch to inject function - #24940

Closed
jelbourn wants to merge 1 commit into
angular:mainfrom
jelbourn:inject-fn
Closed

jelbourn wants to merge 1 commit into
angular:mainfrom
jelbourn:inject-fn

Conversation

@jelbourn

Copy link
Copy Markdown
Contributor

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)`.
@jelbourn
jelbourn requested a review from a team May 18, 2022 22:29
@jelbourn jelbourn closed this May 18, 2022
@angular-automatic-lock-bot

Copy link
Copy Markdown

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot Bot locked and limited conversation to collaborators Jun 18, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant