Skip to content
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

feat(core): add ability to set inputs on ComponentRef #46641

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

pkozlowski-opensource
Copy link
Member

@pkozlowski-opensource pkozlowski-opensource commented Jun 30, 2022

This change adds the setInput method to the ComponentRef with the following benefits:

  • it takes input aliasing into account
  • it marks OnPush components as dirty
  • it triggers NgOnChanges lifecycle hook

Closes #12313
Closes #22567

@mlc-mlapis
Copy link
Contributor

@mlc-mlapis mlc-mlapis commented Jun 30, 2022

@pkozlowski-opensource Great news, thank you.

This change adds the setInput method to the ComponentRef. This
has two benefits:
- it takes input aliasing into account
- it marks OnPush components as dirty
- it triggers NgOnChanges lifecycle hook

Closes angular#12313
Closes angular#22567
@ngbot ngbot bot added this to the Backlog milestone Jun 30, 2022
@pkozlowski-opensource pkozlowski-opensource removed this from the Backlog milestone Jun 30, 2022
@pkozlowski-opensource pkozlowski-opensource added this to the Fixit H1'2022 milestone Jun 30, 2022
@pkozlowski-opensource pkozlowski-opensource added the target: minor label Jun 30, 2022
@pkozlowski-opensource pkozlowski-opensource marked this pull request as ready for review Jun 30, 2022
Copy link
Contributor

@atscott atscott left a comment

This is exciting! I think it would be worth mentioning some more about why in the commit message, not just the what. For example, how this affects testing for components with inputs, how this makes working with dynamic component creation easier (not having to manually call ngOnChanges in code, for example), and the potential for unlocking other features such as binding route params to component inputs.

* component using the `OnPush` change detection strategy. It will trigger execution of the
* `OnChanges` lifecycle hook.
Copy link
Contributor

@atscott atscott Jun 30, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As mentioned in the chat, I think we should be more clear about the statement "it will trigger execution of the OnChanges lifecycle hook. This feels like it's implying ngOnChanges will run immediately but that's not true. It gets run as part of the next change detection.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
action: review comp: core target: minor
Projects
None yet
3 participants