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
feat(Dialog): Allow passing in component @Inputs when opening a dialog #27776
P3An issue that is relevant to core functions, but does not impede progress. Important, but not urgentarea: material/dialogfeatureLabel used to distinguish feature request from other issues
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 componentInstanceafter 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
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.
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.
angular-automatic-lock-bot commented on Oct 23, 2023
P3An issue that is relevant to core functions, but does not impede progress. Important, but not urgentarea: material/dialogfeatureLabel used to distinguish feature request from other issues
Activity
crisbeto commentedon Sep 22, 2023
Actually I think this can be closed. With the changes from #27536 you can call
setInputon the dialog'sComponentRefyourself. This would be more flexible than having aninputsproperty on theDialogConfig, because it allows for the value to change dynamically.cusher commentedon Sep 22, 2023
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
requiredinput.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 aboutsuggest adding a more robust interface for that on the main Angular repo.setInputangular-automatic-lock-bot commentedon Oct 23, 2023
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.