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
In Lifecycle Hooks docs, it's not clear that ngOnChanges is not called when inputs are not used #23017
Comments
This just caught me out as well. The documentation really comes across like ngOnChanges is a requirement of ngOnInit firing, it also doesn't make it clear that ngOnChanges may not fire at all if no data is bound. When in reality, it's merely depicting the order they are called, not that they are related to each other being triggered or not. Would be great to have this cleared up. |
…re bound (angular#42374) fixes angular#23017 PR Close angular#42374
…re bound (angular#42374) fixes angular#23017 PR Close angular#42374
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. |
I'm submitting a...
Current behavior
Lifecycle Hooks page says this about
ngOnChanges()
:and this about
ngOnInit()
:It's not clear from that description that
ngOnChanges()
will not be called if the component is used without providing any inputs.Expected behavior
Documentation should be more clear about
ngOnChanges()
behavior: specifically, if a component has inputs declared but they are not used, thenngOnChanges()
will not be called beforengOnInit()
Minimal reproduction of the problem with instructions
https://stackblitz.com/edit/angular-ngonchanges
What is the motivation / use case for changing the behavior?
Judging from the of the docs, one may have an impression that
ngOnChanges()
will always be called first beforengOnInit()
for a component with inputs, even if those inputs are not used by parent template/component.This may lead to not-so-obvious accidental errors, such as removing
ngOnInit()
if it duplicates start-up logic of a component fromngOnChanges()
.The text was updated successfully, but these errors were encountered: