【发布时间】:2018-09-24 17:17:14
【问题描述】:
我收到来自服务器的字符串响应:
<table><thead><tr> <th scope="col">Home</th> <th scope="col">Page </th> <th scope="col">World </th> <th scope="col">HE </th> <th scope="col">MAN</th> <th scope="col">GO</th></tr></thead><tbody><tr><td>1</td><td>2</td><td>3</td><td>1</td><td>145</td><td>42</td></tr><tr><td>12</td><td>3125</td><td>315</td><td>2554</td><td>5542</td><td>331255</td></tr></tbody></table>
如何将它作为 html 元素直接插入到我的页面中,以便我可以向用户查看 html 表格。
我是 Angular 的新手,下面是我尝试过的东西:
我在我的组件类中创建了一个变量作为 htmltable 并尝试创建一个如下所示的 htmlelemnt
this.htmltable = document.createElement(serverresponse.htmltable)
但它不起作用。
我也试过这种方式:
<div class="dynamically_created_div unique_identifier" #d1></div>
@ViewChild('d1') d1:ElementRef;
this.renderer.appendChild(this.d1, serverresponse.htmltable);
但它不起作用。请建议我这样做的正确方法
【问题讨论】: