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

In Lifecycle Hooks docs, it's not clear that ngOnChanges is not called when inputs are not used #23017

Closed
corg opened this issue Mar 27, 2018 · 2 comments
Assignees
Labels
feature Issue that requests a new feature freq2: medium
Milestone

Comments

@corg
Copy link

corg commented Mar 27, 2018

I'm submitting a...

[x] Documentation issue or request

Current behavior

Lifecycle Hooks page says this about ngOnChanges():

called before ngOnInit() and whenever one or more data-bound input properties change

and this about ngOnInit():

called [...] after the first ngOnChanges()

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, then ngOnChanges() will not be called before ngOnInit()

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 before ngOnInit() 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 from ngOnChanges().

@ngbot ngbot bot added this to the needsTriage milestone Mar 27, 2018
@corg corg changed the title In Lifecycle Hooks docs, it's not clear that ngOnChanges is not called when inputs are not provided In Lifecycle Hooks docs, it's not clear that ngOnChanges is not called when inputs are not used Mar 27, 2018
@IgorMinar IgorMinar added comp: docs area: core Issues related to the framework runtime labels Mar 29, 2018
@mhevery mhevery added freq2: medium severity3: broken and removed area: core Issues related to the framework runtime labels Apr 3, 2018
@jenniferfell jenniferfell added feature Issue that requests a new feature and removed severity3: broken labels Apr 25, 2018
@ngbot ngbot bot modified the milestones: needsTriage, Backlog Apr 25, 2018
@christopher-kiss
Copy link

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.

@angular-automatic-lock-bot
Copy link

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 27, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature Issue that requests a new feature freq2: medium
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants