Skip to content

Commit

Permalink
feat: TemplateRef can access the dialog so it can control the modal a…
Browse files Browse the repository at this point in the history
…nd access the context
  • Loading branch information
Shlomi Assaf (shlassaf) committed Aug 30, 2016
1 parent a031924 commit 5e6c59e
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/components/angular2-modal/providers/modal.ts
Expand Up @@ -92,7 +92,7 @@ export abstract class Modal {
if (typeof content === 'string') {
nodes = [[this.renderer.createText(null, `${content}`)]];
} else if (content instanceof TemplateRef) {
nodes = [this.overlay.defaultViewContainer.createEmbeddedView(content, dialogRef.context).rootNodes];
nodes = [this.overlay.defaultViewContainer.createEmbeddedView(content, { dialogRef }).rootNodes];
} else {
nodes = [dialogRef.overlayRef.instance.addEmbeddedComponent({ component: content, bindings: b }).rootNodes];
}
Expand Down
Expand Up @@ -10,14 +10,17 @@
</div>
</div>
</demo-head>
<template #templateRef>
<template #templateRef let-dialogRef="dialogRef" let-ctx="dialogRef.context">
<div style="padding: 10px">
<div class="page-header">
<h1>TemplateRef Example</h1>
</div>
<div class="jumbotron">
<h1>Hello, modal!</h1>
<p> I'm a declarative TemplateRef!</p>
<p>I'm a declarative TemplateRef!</p>
<p>TemplateRef can also access the DialogRef for context and modal control:</p>
<pre>{{ ctx | json }}</pre>
<button class="btn btn-primary" (click)="dialogRef.close(true)">Close Me</button>
</div>
</div>
</template>
Expand Up @@ -46,7 +46,7 @@ export class BootstrapDemoPage {
{
text: 'TemplateRef content',
factory: () => this.modal
.open(this.templateRef, new BSModalContextBuilder().isBlocking(false).toOverlayConfig())
.open(this.templateRef, new BSModalContextBuilder({ abd: 123 } as any).isBlocking(false).toOverlayConfig())
},
{
text: 'Custom Modal content',
Expand Down
5 changes: 4 additions & 1 deletion src/demo/app/vex-demo/vex-demo.tpl.html
Expand Up @@ -23,14 +23,17 @@
<br><br>
</div>
</demo-head>
<template #templateRef>
<template #templateRef let-dialogRef="dialogRef" let-ctx="dialogRef.context">
<div style="padding: 10px">
<div class="page-header">
<h1>TemplateRef Example</h1>
</div>
<div class="jumbotron">
<h1>Hello, modal!</h1>
<p> I'm a declarative TemplateRef!</p>
<p>TemplateRef can also access the DialogRef for context and modal control:</p>
<pre>{{ ctx | json }}</pre>
<button class="btn btn-primary" (click)="dialogRef.close(true)">Close Me</button>
</div>
</div>
</template>

0 comments on commit 5e6c59e

Please sign in to comment.