components icon indicating copy to clipboard operation
components copied to clipboard

Reduced reusability because of MatDialogRef's requriments?

Open FDN73 opened this issue 8 years ago • 5 comments

Proposal. Suppose I have a component I want to reuse in different other components to be opened as a dialog. MatDialogRef's current requirement to pass the "opener" component's type does not allow such use case. If not using MatDialogRef, it have to be the openers's responsibility to close the dialog, forcing some kind of communication between the two components. It would be nice to be able to instantiate a MatDialogRef derivative which requires no opener type, and just allows to close the dialog. This is useful in frameworks like NGRX: I just issue a new action from my dialog and I just want it to close itself, the dialog opener does not need to know anything, as it can watch the application's state.

FDN73 avatar May 25 '18 09:05 FDN73

I think youre wrong, to instantiate the dialog ref you dont need the opener component you should use the component itself, i mean if your dialog component is DialogComponent you should instantiate dialog ref like this: public dialogRef: MatDialogRef<DialogComponent> in the constructor. You can see an example here.

The only thing a bit anoying is that you need to add the dialog component as an entry component, but if you have a shared module you can add it there and thats it, you can use that dialog anywhere

andresbm05 avatar May 26 '18 08:05 andresbm05

I don't also understand the request:

  • use MatDialogClose button component to close the dialog from within the dialog
  • use MatDialogRef.close() to close the dialog from outside (i.e. the opener) or inside (the dialog itself)
  • use MatDialog.closeAll() to close all dialogs without a MatDialogRef

Also for opnening a dialog, all you do is MatDialog.open(YourDialog) which does not require the opener at all and returns the MatDialogRef.

This should give you all possible options to close the dialog from either outside or inside the dialog without ever having a strict dependency between the opener and the dialog.

pfeigl avatar May 27 '18 11:05 pfeigl

Didn't know about the MatDialogClose button component - here https://material.angular.io/components/categories I could not find any reference to it but by googling it I've found the documentation. Thank you, this is what I need.

FDN73 avatar May 29 '18 12:05 FDN73

The overview: https://material.angular.io/components/dialog/overview#dialog-content The API: https://material.angular.io/components/dialog/api#MatDialogClose

Anyways, you're welcome! Guess you can than close this ticket, when you have everything you need.

pfeigl avatar May 29 '18 12:05 pfeigl

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.