I'm using UI Library Ant Design in Angular Project. I'm trying to render dynamic HTML inside but using UI library component, like this
My component.ts:
test : any;
ngAfterViewInit() {
setTimeout(() => {
this.test = this.domSanitizer.bypassSecurityTrustHtml('<nz-table>
<thead>
<td>Header 1</td>
<td>Header 2</td>
</thead>
<tbody>
<tr>
<td>Value 1</td>
<td>Value 2</td>
</tr>
</tbody>
</nz-table>')
}, 0);
}
My component.html:
<div [innerHtml]="test"></div>
But this is what I received
Header 1Header 2Value 1Value 2
So, how I can render dynamic HTML inside AntDesign's Nz-Table Component?
You should not use
innerHTMLbut an*ngFor. Your code example is very poor but I will do my best:in your HTML templare
As you can see
tableDatacan be anything, you can push row into it and the table will update. You can also get the value from an API or whatever you want. You can also use JSON object instead of all this arrays and use keyvalue pairs if you want.