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 }}
This repository was archived by the owner on Oct 7, 2020. It is now read-only.
A dialog is opened by calling the <codeclass="docs-markdown-code">open</code> method with a component to be loaded and an optional config object. The <codeclass="docs-markdown-code">open</code> method will return an instance of <codeclass="docs-markdown-code">MdcDialogRef</code>:
249
-
<pre>
250
-
let dialogRef = dialog.open(UserProfileComponent, {{"{
The <codeclass="docs-markdown-code">MdcDialogRef</code> provides a handle on the opened dialog. It can be used to close the dialog and to receive notification when the dialog has been closed.
<p>Components created via <codeclass="docs-markdown-code">MdcDialog</code> can inject <codeclass="docs-markdown-code">MdcDialogRef</code> and use it to close the dialog in which they are contained. When closing, an optional result value can be provided. This result value is forwarded as the result of the <codeclass="docs-markdown-code">afterClosed</code> promise.</p>
<h3class="demo-content__headline">Sharing data with the Dialog component</h3>
278
279
If you want to share data with your dialog, you can use the <codeclass="docs-markdown-code">data</code> option to pass information to the dialog component.
279
-
<pre>
280
-
let dialogRef = dialog.open(YourDialog, {{"{
281
-
data: {name: this.name, animal: this.animal}
282
-
}"}});
283
-
</pre>
280
+
281
+
<pre>
282
+
let dialogRef = dialog.open(YourDialog, {{"{
283
+
data: {name: this.name, animal: this.animal}
284
+
}"}});
285
+
</pre>
284
286
285
287
To access the data in your dialog component.
286
-
<pre>
287
-
<![CDATA[
288
-
import { Component, Inject } from '@angular/core';
289
-
import { MdcDialogRef, MDC_DIALOG_DATA } from '@angular-mdc/web';
@Inject(MDC_DIALOG_DATA) public data: DialogData) {
296
-
userName: string = data.name;
297
-
}
298
-
}]]>
299
-
</pre>
300
288
289
+
<pre><codehighlightcode="import { Component, Inject } from '@angular/core';
290
+
import {
291
+
MdcDialogRef,
292
+
MDC_DIALOG_DATA
293
+
} from '@angular-mdc/web';
294
+
295
+
@Component({
296
+
// ...
297
+
})
298
+
export class YourDialog {
299
+
constructor(
300
+
public dialogRef: MdcDialogRef<YourDialog>,
301
+
@Inject(MDC_DIALOG_DATA) data: DialogData) {
302
+
userName: string = data.name;
303
+
}
304
+
}"></code></pre>
301
305
<h3class="demo-content__headline">Configuring dialog content via entryComponents</h3>
302
306
<pmdcBody2>Because <codeclass="docs-markdown-code">MdcDialog</code> instantiates components at run-time, the Angular compiler needs extra information to create the necessary
303
307
ComponentFactory for your dialog content component.</p>
304
308
<pmdcBody2>For any component loaded into a dialog, you must include your component
305
309
class in the list of <codeclass="docs-markdown-code">entryComponents</code> in your NgModule definition so that the Angular compiler knows to create the ComponentFactory.</p>
0 commit comments