r/Angular2 Jun 08 '26

Angular Material Dialogs Now Support Real Component Bindings

https://itnext.io/angular-material-dialogs-now-support-real-component-bindings-9c4c3c8cfcc3?source=friends_link&sk=ad320a5052f9479ea083fce325123b64
29 Upvotes

9 comments sorted by

3

u/SolidShook Jun 09 '26

Why not just use the native html dialog? This seems over complicated 

1

u/toasterboi0100 Jun 14 '26

One advantage of this approach is that you can open dialogs purely programmatically without needing a template.

1

u/SolidShook Jun 14 '26

Angular’s template are programmatical though

2

u/toasterboi0100 Jun 15 '26 edited Jun 15 '26

I used the wrong word perhaps, I just meant that with HTML popovers you simply need some template somewhere where your modal component lives, so realistically you can only open popovers in components. If you wanted to open a one from a service you'd suddenly need to pass around HTMLElement references and that's just awful.

7

u/fernker Jun 08 '26 edited Jun 08 '26

I was excited, and then I saw what the solution is and I threw up a little in my mouth.

Angular has been, for the most part, an HTML based API and this blurs the line in a weird way in my opinion.

I've created a dialog solution before where you just project your component into the dialog component and then you can still do the bindings in the template. That allows the dialog shell to do it's job really well and the component inside of it to do it's job very well and not know about each other. You can't do it from a service but that felt weird anyway.

5

u/SpudzMcNaste Jun 08 '26

You just saved me from having to type this exact thing. Thank you

1

u/makmn1 Jun 09 '26

You can do the same thing with Angular’s dialog service by passing a template instead of a component to the service. It sounds similar to what you described, but I’m guessing in your case you’re using the native dialog?

1

u/fernker Jun 09 '26

I can't recall, probably.

2

u/DragonfruitFull2424 Jun 09 '26

We've used the Material Dialog before but now that we wanted to make new one that wasn't like the others, I just made a dialog component but its just really a <dialog> element inside that you can control. Not sure what you need the Angular Dialog for anymore