angular
angular copied to clipboard
fix(core): only set input on specific instance in ComponentRef.setInput
ComponentRef.setInput
works by calling setInputsForProperty
internally. It can be problematic, because it will set the all inputs on the specific node matching the passed-in name, including other directives that aren't associated with the ComponentRef
. Currently this isn't a problem, because the only way to get a ComponentRef
is as a result of ComponentFactory.create
and there is no way to apply other directives through there, however I see a couple of ways that it can manifest itself in the future:
- Once the runtime for host directives is implemented (after #46868), users will be able to apply directives to the root component.
- If we were to make it possible to inject
ComponentRef
in the future.
These changes add some extra logic so that the input is only assigned to the component instance that is associated with the ComponentRef
.
You're right that the intent with host directives is for them to work as if they were applied inside a template. I think that this case is different, because you have a reference pointing to a specific component class. As a user, I would find it odd if calling setInput
would modify the input of a host directive I have no access to.
Small aside regarding tests: I have it on my list to add tests for this specific use case once I start working on the runtime implementation.
You're right that the intent with host directives is for them to work as if they were applied inside a template. I think that this case is different, because you have a reference pointing to a specific component class. As a user, I would find it odd if calling setInput would modify the input of a host directive I have no access to.
@crisbeto I can see it as a different way of looking at the problem. Again, the initial assumption was that it does behave as a regular input. And it does make total sense to me in case of host directives. We can certainly review this assumption. Maybe an item on the fwk sync agenda?
Sure, let's discuss it. I've added it to the agenda.
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.