question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

setInput() triggers ngOnChanges and mark component when it should not

See original GitHub issue

Which @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.

image

https://user-images.githubusercontent.com/10418323/190913482-70c5da4c-1855-479f-a744-20fae0afff8e.mp4

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:open
  • Created a year ago
  • Reactions:37
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
pkozlowski-opensourcecommented, Sep 19, 2022

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 inside setInput, although it is not clear what the design should be and if this is the right direction at all…

0reactions
angular-robot[bot]commented, Sep 28, 2022

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found