Skip to content

feat(Dialog): Allow passing in component @Inputs when opening a dialog #27776

Closed

Description

@cusher

Feature Description

To pass data into a dialog, the current suggested pattern is to set data on the DialogConfig parameter when calling open, and then inject the data into the dialog component using the DIALOG_DATA injection token.

Another option is to set the inputs on the componentInstance after the dialog is opened, however if the component relies on the input being set before initialization, this can run into problems.

Angular 16 added the ability to pass in component @Inputs as in route params, which allows the removal of basic wrapper components and per-component boilerplate for the most common cases of passing in data through the Router. It would be nice to see this change also reflected in Dialog.

Use Case

  • Enables using an existing component that takes in @Input(s) in a basic Dialog without creating a wrapper dialog component that exists solely to pass along injected data (admittedly, of questionable value, since many dialogs will need dialog-specific UI/behavior)
  • Allows for passing in data to a dialog component in a more symmetric way with non-dialog components
  • Eliminates the need to create a dialog data specific interface for type-safe parameter passing to dialog components

Activity

  1. added
    feature
    needs triage
    on Sep 8, 2023
  2. added
    P3
    and removed
    needs triage
    on Sep 8, 2023
  3. crisbeto commented on Sep 22, 2023

    @crisbeto
    Member

    Actually I think this can be closed. With the changes from #27536 you can call setInput on the dialog's ComponentRef yourself. This would be more flexible than having an inputs property on the DialogConfig, because it allows for the value to change dynamically.

  4. cusher commented on Sep 22, 2023

    @cusher
    ContributorAuthor

    Given the choice between setting inputs via an untyped name string, or creating boilerplate wrapper components to pass in the inputs while maintaining type checking throughout, I would stick with the latter 10 out of 10 times. And that's before considering things that can only be caught if all inputs are set at creation time, e.g. a missing required input.

    That being said, in hindsight it makes way more sense to use whatever interface is exposed by Angular itself for setting inputs on dynamically created components, rather than creating a one-off solution for Dialog specifically. So perhaps I'll complain about setInput suggest adding a more robust interface for that on the main Angular repo.

  5. angular-automatic-lock-bot commented on Oct 23, 2023

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

  6. locked and limited conversation to collaborators on Oct 23, 2023
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

    P3area: material/dialogfeature

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions