You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
It's impossible to set signal input of hosted directive - hostDirectives #55082
Which @angular/* package(s) are relevant/related to the feature request?
core
Description
When composing directives with signal inputs input(), it's impossible to set the inputs of hosted directive.
We could do it with normal inputs for example injecting this directive and then setting it's inputs.
Proposed solution
Add signalInput.setInit(val) method that will work but only before first change detection occure - so basicly only in constructors.
I propose name setInit(val) or init(val) to distinct it from set() that can be used anytime with model() or WrittableSignal.
Setting required inputs with setInit should not result with required input not set diganostic. Mayby additional option to hostedDirectiives would be requred for this to work which will indicate that the required input is set programaticly - this could be made separate issue if required.
Alternatives considered
Modify hosted directive to use model instead of input but it changes how hosted directive behaves. Especially when used in other palces.
This is by design - host directives only have the ability to forward inputs, not set them directly. (they don't have access to a programmatic setInput).
Note that through DI, it was sometimes possible to obtain a reference to the directive instance and manually set properties which might also be inputs. While this can have similar effects, it's not the same thing as setting inputs - it doesn't run ngOnChanges lifecycle hooks, doesn't mark for check, doesn't work with protected inputs, etc.
It's a separate question whether host directives should have the ability to set non-forwarded inputs (#50510) - I will close this issue as a duplicate of that discussion.
Activity
alxhub commentedon Mar 28, 2024
This is by design - host directives only have the ability to forward inputs, not set them directly. (they don't have access to a programmatic
setInput).Note that through DI, it was sometimes possible to obtain a reference to the directive instance and manually set properties which might also be inputs. While this can have similar effects, it's not the same thing as setting inputs - it doesn't run
ngOnChangeslifecycle hooks, doesn't mark for check, doesn't work withprotectedinputs, etc.It's a separate question whether host directives should have the ability to set non-forwarded inputs (#50510) - I will close this issue as a duplicate of that discussion.
angular-automatic-lock-bot commentedon Apr 28, 2024
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.