Reputation: 3829
I am trying to pass HTML to mat dialog but it shows [object HTMLTableElement]
in the dialog instead of Table HTML.
Steps I have Tried:
Made an Element Ref in template as below:
<table hidden #contentTable><th></th><tr></tr></table>
Accessed ViewChild in component as
@ViewChild('contentTable', { read: ElementRef }) contentTable: ElementRef<any>;
Passed this as Data in DialogComponent as
const tableData = this.contentTable.nativeElement;
const dialogRef = this.dialog.open(GeneralDialogComponent, {
panelClass: 'customDialog',
data: {
title: `${data.count}`,
content: tableData
}
});
In DialogComponent, accessed data content as below:
// method in component
getHtml(html) {
return this.domSanitizer.bypassSecurityTrustHtml(html);
}
Then in HTML accessed like this:
<div [innerHTML]="getHtml(data?.content)"></div>
but it does not print Table instead it prints [object HTMLTableElement]
.
Screenshot as below:
Any leads please?
Upvotes: 2
Views: 2680
Reputation: 11982
you should pass the innerHtml of elementRef not itself:
<div [innerHTML]="getHtml(data?.content.innerHTML)"></div>
Upvotes: 2