setInput() triggers ngOnChanges and mark component when it should not
See original GitHub issueWhich @angular/* package(s) are the source of the bug?
core
Is this a regression?
No
Description
I thought ComponentRef.setInput() will:
- set input
- mark component when neccessary
- make sure ngOnChanges is called when neccessary
However it is called when OnPush component is used and input doesn’t change so i think it is not correct behavior.
Please provide a link to a minimal reproduction of the bug
https://stackblitz.com/edit/angular-ivy-yo1znz?file=src/app/hello.component.ts
Please provide the exception or error you saw
No response
Please provide the environment you discovered this bug in (run ng version
)
No response
Anything else?
Of course we can check it manually, but only “component.instance” is available for the developers from “PUBLIC API” - and that’s problem in case of setters without getters etc.
Issue Analytics
- State:
- Created a year ago
- Reactions:37
- Comments:6 (4 by maintainers)
Top Results From Across the Web
ngOnChanges only runs when the Input change comes from a ...
ngOnChanges only runs when the Input change comes from a template binding like . If you set it manually like this component.
Read more >ngOnChanges not firing for nested object - Stack Overflow
My map component needs to use ngOnChanges as a trigger to redraw markers on a Google Map. The problem is that ngOnChanges does...
Read more >Testing Components – Testing Angular
Introduction to testing Angular Components with Angular's TestBed.
Read more >Netanel Basal on Twitter: " The next version of @angular ...
Additional benefits: - It will trigger the `NgOnChanges` lifecycle hook - Works with input aliasing - Marks OnPush components for check.
Read more >'Dumb' Angular — Input Setter/Getter vs NgOnChanges
Angular components have multiple ways to share information with ... Here, both Input bindings and NgOnChanges would not be triggered due to ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
ngOnChanges
doesn’t do prev / current comparison, this happens before input values are updated (and hence it is not implemented in the current version of the API). So it is not a question of the public API availability. Currently you would have to remember prev values and do the comparison on your side. As I’ve mentioned, this is sth we might consider doing insidesetInput
, although it is not clear what the design should be and if this is the right direction at all…This feature request is now candidate for our backlog! In the next phase, the community has 60 days to upvote. If the request receives more than 20 upvotes, we’ll move it to our consideration list.
You can find more details about the feature request process in our documentation.