简体   繁体   English

HTML表字符串到DOM元素

[英]HTML table string to DOM element

I am new to Angular 4 (and html as well) . 我是Angular 4(和html)的新手。 I have ac# datatable object and I want to present it in an Angular application. 我有一个ac#datatable对象,我想在Angular应用程序中展示它。 So I turned this datatable to an HTML string such as : 因此,我将此数据表转换为HTML字符串,例如:

<table class="table table - striped">
            <tr><td>Name</td><td>BI</td><td>Run Time</td><td>Missing</td><td>Stale</td><td>Jump</td></tr>
            <tr><td>something</td><td>223</td><td>4/10/2018 7:05:07 AM</td><td>0</td><td>1</td><td>0</td></tr>

        </table>

and now I try to understand how to dynamically integrate this into my HTML file. 现在,我尝试了解如何将其动态集成到HTML文件中。 What kind of binding should I use? 我应该使用哪种绑定?

in your component's HTML add a div as: 在组件的HTML中,将div添加为:

<div [innerHTML]="tableHTML"></div>

In component declare a variable and update this value whenever you get updated HTML string of table. 在组件中声明一个变量,并在获取表的更新的HTML字符串时更新此值。 It can be done as: 可以通过以下方式完成:

tableHTML: any;

onAfterViewInit(){ 
  tableHTML = <updated HTML string> // tableHTML should be updated whenever you are getting data from back-end.
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM