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
Feature: add method to change inputs in ComponentRef #22567
Comments
This is a very cool idea. It should also allow to test OnPush components without adding a wrapper component, so should at least partially resolve #12313. |
Just a heads up that we kicked off a community voting process for your feature request. There are 20 days until the voting process ends. Find more details about Angular's feature request process in our documentation. |
Is it still being considered? I think it would be a very useful feature. |
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
This change adds the setInput method to the ComponentRef. Previously users had to call `componentRef.instance['inputName']` to change inputs of a dynamically created component. This had several problems: * OnPush components were not marked for check and thus very difficult to test; * input aliasing was not take into account - a property name on a component could have been different from the actual input name so setting input properties was fragile; * manually setting input propertie would NOT trigger the `NgOnChanges` lifecycle hook. This modifications unifies `@Input` accross dynamically created components and the ones referenced in templates. This also opens doors to other changes: as an example router could use this new method to set `@Input`s from router params. Closes angular#12313 Closes angular#22567
This change adds the setInput method to the ComponentRef. Previously users had to call `componentRef.instance['inputName']` to change inputs of a dynamically created component. This had several problems: * OnPush components were not marked for check and thus very difficult to test; * input aliasing was not take into account - a property name on a component could have been different from the actual input name so setting input properties was fragile; * manually setting input propertie would NOT trigger the `NgOnChanges` lifecycle hook. This modifications unifies `@Input` accross dynamically created components and the ones referenced in templates. This also opens doors to other changes: as an example router could use this new method to set `@Input`s from router params. Closes angular#12313 Closes angular#22567
This change adds the setInput method to the ComponentRef. Previously users had to call `componentRef.instance['inputName']` to change inputs of a dynamically created component. This had several problems: * OnPush components were not marked for check and thus very difficult to test; * input aliasing was not take into account - a property name on a component could have been different from the actual input name so setting input properties was fragile; * manually setting input propertie would NOT trigger the `NgOnChanges` lifecycle hook. This modifications unifies `@Input` accross dynamically created components and the ones referenced in templates. This also opens doors to other changes: as an example router could use this new method to set `@Input`s from router params. Closes angular#12313 Closes angular#22567
This change adds the setInput method to the ComponentRef. Previously users had to call `componentRef.instance['inputName']` to change inputs of a dynamically created component. This had several problems: * OnPush components were not marked for check and thus very difficult to test; * input aliasing was not take into account - a property name on a component could have been different from the actual input name so setting input properties was fragile; * manually setting input propertie would NOT trigger the `NgOnChanges` lifecycle hook. This modifications unifies `@Input` accross dynamically created components and the ones referenced in templates. This also opens doors to other changes: as an example router could use this new method to set `@Input`s from router params. Closes angular#12313 Closes angular#22567
This change adds the setInput method to the ComponentRef. Previously users had to call `componentRef.instance['inputName']` to change inputs of a dynamically created component. This had several problems: * OnPush components were not marked for check and thus very difficult to test; * input aliasing was not take into account - a property name on a component could have been different from the actual input name so setting input properties was fragile; * manually setting input propertie would NOT trigger the `NgOnChanges` lifecycle hook. This modifications unifies `@Input` accross dynamically created components and the ones referenced in templates. This also opens doors to other changes: as an example router could use this new method to set `@Input`s from router params. Closes angular#12313 Closes angular#22567
This change adds the setInput method to the ComponentRef. Previously users had to call `componentRef.instance['inputName']` to change inputs of a dynamically created component. This had several problems: * OnPush components were not marked for check and thus very difficult to test; * input aliasing was not take into account - a property name on a component could have been different from the actual input name so setting input properties was fragile; * manually setting input propertie would NOT trigger the `NgOnChanges` lifecycle hook. This modifications unifies `@Input` accross dynamically created components and the ones referenced in templates. This also opens doors to other changes: as an example router could use this new method to set `@Input`s from router params. Closes angular#12313 Closes angular#22567
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
To change inputs of component creates via ComponentFactory we need to access component instance directly, like that:
Expected behavior
There should exist a method on ComponentFactory that changes inputs, for example:
Minimal reproduction of the problem with instructions
N/A
What is the motivation / use case for changing the behavior?
Changing properties on component instance won't call ngOnChanges. You have to do it manually, and that's really annoying because You really can't assume that it's not necessary for component to work correctly.
Calling changeInputs should also call ngOnChanges on component instance. It's also might be a good idea to delay it until change detection is triggered or trigger change detection automatically when changeInputs is called, so ngOnChanges would be called only once before ngDoCheck. Again, some components may rely on ngOnChanges being followed by ngDoCheck.
The text was updated successfully, but these errors were encountered: