Components: Dynamically Loaded Components(Dialog, Toast)

Created on 29 Jun 2016  路  7Comments  路  Source: angular/components

Bug, feature request, or proposal:

I noticed that the Angular team hasn't started on components that needs to be dynamically loaded such as the MD Dialog and MD Toast present in Angular Material 1. There is no best practice in how to load and destroy elements like these in Angular 2. Any ideas on how this can be achieved?

In Angular Material 1, we could also pass data into the dialog and output data when the dialog is destroyed/hidden(promise based).

What is the expected behavior?

Dynamically load components into the view for modals, toasts and the likes

What is the current behavior?

No proper documentation

What is the use-case or motivation for changing an existing behavior?

If the Angular team has started on at least one of these components(dialog or toast), we may start exploring the possibilities of how to best handle dynamically loaded components and create our own

Which versions of Angular, Material, OS, browsers are affected?

Angular 2.0.0-rc.3
Angular Material 2.0.0-alpha.5-2

Most helpful comment

We can pass any data to dynamic components by using of ng-content.

In case of Modal we actually can place our html things inside any component that gonna use this Modal because modal should not draw itself before call of popup() or something. Also modal should have absolute position and z-index so there is no any reason for modal to be pasted somewhere at the special place (like root component or etc).

You can just write your modal where you want, pass data by using of ng-content and finally draw it when *ngif becomes true.

From the other hand it will be cool if modal component can be written only ones somewhere in root component and then just been reused when need to.

All 7 comments

We can pass any data to dynamic components by using of ng-content.

In case of Modal we actually can place our html things inside any component that gonna use this Modal because modal should not draw itself before call of popup() or something. Also modal should have absolute position and z-index so there is no any reason for modal to be pasted somewhere at the special place (like root component or etc).

You can just write your modal where you want, pass data by using of ng-content and finally draw it when *ngif becomes true.

From the other hand it will be cool if modal component can be written only ones somewhere in root component and then just been reused when need to.

Thanks for the reply @TheCaptainDate . However, in Angular Material 1.x, this is not how dialogs and toasts work. They just get injected by a service-like module($mdDialog) which does not require the explicit declaration of a selector element(e.g my-dialog) in the document. These element will just get dynamically injected into the documents body. I'm keen to know what the Angular team thinks and whether they can give a better insight.

@borislemke take a look

@TheCaptainDate thanks mate! Exactly what I was looking for. Will keep track of it

ng-content solved my problem. Thanks

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

LoganDupont picture LoganDupont  路  3Comments

MurhafSousli picture MurhafSousli  路  3Comments

theunreal picture theunreal  路  3Comments

dzrust picture dzrust  路  3Comments

jelbourn picture jelbourn  路  3Comments