Send data to a TemplateRef MatDialog











up vote
1
down vote

favorite












How to get data sent to a MatDialog that is a ng-template?



Template



<button mat-button (click)="openDialog()">Open</button>

<ng-template #dialogRef>
{{data?}} <!-- <<< Here is the problem data is undefined -->
</ng-template>


Component



export class SomeComponent {
@ViewChild("dialogRef") dialogRef: TemplateRef<any>;

constructor(private dialog: MatDialog) { }

openDialog(): void {
this.dialog.open(this.dialogRef, { data: "some data" });
}
}









share|improve this question
























  • What data you want to send??
    – Abhishek Ekaanth
    2 days ago










  • Any kind of data, some objects, in this case a simple string (data: "some data"). It is something possible to achieve when using a separate component for the dialog (with @Inject(MAT_DIALOG_DATA) public data in the component constructor) but I don't know how to access it with the dialog as a simple ng-template.
    – Sébastien
    2 days ago















up vote
1
down vote

favorite












How to get data sent to a MatDialog that is a ng-template?



Template



<button mat-button (click)="openDialog()">Open</button>

<ng-template #dialogRef>
{{data?}} <!-- <<< Here is the problem data is undefined -->
</ng-template>


Component



export class SomeComponent {
@ViewChild("dialogRef") dialogRef: TemplateRef<any>;

constructor(private dialog: MatDialog) { }

openDialog(): void {
this.dialog.open(this.dialogRef, { data: "some data" });
}
}









share|improve this question
























  • What data you want to send??
    – Abhishek Ekaanth
    2 days ago










  • Any kind of data, some objects, in this case a simple string (data: "some data"). It is something possible to achieve when using a separate component for the dialog (with @Inject(MAT_DIALOG_DATA) public data in the component constructor) but I don't know how to access it with the dialog as a simple ng-template.
    – Sébastien
    2 days ago













up vote
1
down vote

favorite









up vote
1
down vote

favorite











How to get data sent to a MatDialog that is a ng-template?



Template



<button mat-button (click)="openDialog()">Open</button>

<ng-template #dialogRef>
{{data?}} <!-- <<< Here is the problem data is undefined -->
</ng-template>


Component



export class SomeComponent {
@ViewChild("dialogRef") dialogRef: TemplateRef<any>;

constructor(private dialog: MatDialog) { }

openDialog(): void {
this.dialog.open(this.dialogRef, { data: "some data" });
}
}









share|improve this question















How to get data sent to a MatDialog that is a ng-template?



Template



<button mat-button (click)="openDialog()">Open</button>

<ng-template #dialogRef>
{{data?}} <!-- <<< Here is the problem data is undefined -->
</ng-template>


Component



export class SomeComponent {
@ViewChild("dialogRef") dialogRef: TemplateRef<any>;

constructor(private dialog: MatDialog) { }

openDialog(): void {
this.dialog.open(this.dialogRef, { data: "some data" });
}
}






angular angular-material






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 2 days ago

























asked 2 days ago









Sébastien

540720




540720












  • What data you want to send??
    – Abhishek Ekaanth
    2 days ago










  • Any kind of data, some objects, in this case a simple string (data: "some data"). It is something possible to achieve when using a separate component for the dialog (with @Inject(MAT_DIALOG_DATA) public data in the component constructor) but I don't know how to access it with the dialog as a simple ng-template.
    – Sébastien
    2 days ago


















  • What data you want to send??
    – Abhishek Ekaanth
    2 days ago










  • Any kind of data, some objects, in this case a simple string (data: "some data"). It is something possible to achieve when using a separate component for the dialog (with @Inject(MAT_DIALOG_DATA) public data in the component constructor) but I don't know how to access it with the dialog as a simple ng-template.
    – Sébastien
    2 days ago
















What data you want to send??
– Abhishek Ekaanth
2 days ago




What data you want to send??
– Abhishek Ekaanth
2 days ago












Any kind of data, some objects, in this case a simple string (data: "some data"). It is something possible to achieve when using a separate component for the dialog (with @Inject(MAT_DIALOG_DATA) public data in the component constructor) but I don't know how to access it with the dialog as a simple ng-template.
– Sébastien
2 days ago




Any kind of data, some objects, in this case a simple string (data: "some data"). It is something possible to achieve when using a separate component for the dialog (with @Inject(MAT_DIALOG_DATA) public data in the component constructor) but I don't know how to access it with the dialog as a simple ng-template.
– Sébastien
2 days ago












1 Answer
1






active

oldest

votes

















up vote
1
down vote



accepted










It should be available through template variable:



<ng-template #dialogRef let-data>
^^^^^^^^
{{data}}
</ng-template>





share|improve this answer





















  • Perfect, thanks!
    – Sébastien
    2 days ago











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53239164%2fsend-data-to-a-templateref-matdialog%23new-answer', 'question_page');
}
);

Post as a guest
































1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
1
down vote



accepted










It should be available through template variable:



<ng-template #dialogRef let-data>
^^^^^^^^
{{data}}
</ng-template>





share|improve this answer





















  • Perfect, thanks!
    – Sébastien
    2 days ago















up vote
1
down vote



accepted










It should be available through template variable:



<ng-template #dialogRef let-data>
^^^^^^^^
{{data}}
</ng-template>





share|improve this answer





















  • Perfect, thanks!
    – Sébastien
    2 days ago













up vote
1
down vote



accepted







up vote
1
down vote



accepted






It should be available through template variable:



<ng-template #dialogRef let-data>
^^^^^^^^
{{data}}
</ng-template>





share|improve this answer












It should be available through template variable:



<ng-template #dialogRef let-data>
^^^^^^^^
{{data}}
</ng-template>






share|improve this answer












share|improve this answer



share|improve this answer










answered 2 days ago









yurzui

89.6k10173197




89.6k10173197












  • Perfect, thanks!
    – Sébastien
    2 days ago


















  • Perfect, thanks!
    – Sébastien
    2 days ago
















Perfect, thanks!
– Sébastien
2 days ago




Perfect, thanks!
– Sébastien
2 days ago


















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53239164%2fsend-data-to-a-templateref-matdialog%23new-answer', 'question_page');
}
);

Post as a guest




















































































Popular posts from this blog

Bressuire

Vorschmack

Quarantine