Skip to content

It's impossible to set signal input of hosted directive - hostDirectives #55082

Closed as not planned

Description

@kbrilla

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.

Activity

  1. alxhub commented on Mar 28, 2024

    @alxhub
    Member

    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.

  2. angular-automatic-lock-bot commented on Apr 28, 2024

    @angular-automatic-lock-bot

    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.

  3. locked and limited conversation to collaborators on Apr 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions