最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to render HTML which is in array in angular - Stack Overflow

programmeradmin4浏览0评论

I have a array in which one of the object contains HTML element. I wanted to render it in angular.

This is the array:

{
name: "rules", 
key: "rules", 
value_before: "<tr><td>revisit_in_some_days</td><td>less_then</td>td>r.input_data</td>"
}

I've tried multi for loops for angular.

I want table of the response in angular frontened.

I have a array in which one of the object contains HTML element. I wanted to render it in angular.

This is the array:

{
name: "rules", 
key: "rules", 
value_before: "<tr><td>revisit_in_some_days</td><td>less_then</td>td>r.input_data</td>"
}

I've tried multi for loops for angular.

I want table of the response in angular frontened.

Share Improve this question edited Jun 18, 2019 at 6:03 Ryan Nghiem 2,4582 gold badges21 silver badges31 bronze badges asked Jun 18, 2019 at 6:01 Kunal DholiyaKunal Dholiya 3852 gold badges6 silver badges21 bronze badges 4
  • Note that the HTML in there is malformed (</td>td> - typo?) and inplete (part of a HTML table). – schnaader Commented Jun 18, 2019 at 6:05
  • you have typing mistakes near less_then</td>. unopened td tag. and missing closing tr tag – Alok Mali Commented Jun 18, 2019 at 6:06
  • Yes, It is there. – Kunal Dholiya Commented Jun 18, 2019 at 6:07
  • Possible duplicate of Angular2 - Interpolate string with html – Joel Joseph Commented Jun 18, 2019 at 7:29
Add a ment  | 

3 Answers 3

Reset to default 5

you should use [innerHTML] directive that es with angular. Usage:

data = [
  {
    value_before: '<div>some content</div>'
  },
  {
    value_before: '<div>some content1</div>'
  }
];

in your .html

<div *ngFor="let item of data">
  <div [innerHTML]="item.value_before"></div>
</div>

you should use [innerHTML] directive that es with angular by default. Like:

<ul><li *ngFor="let res of trackLogList[key]" [innerHTML]="res"></li></ul>

Assuming you will be placing the HTML inside a table,you can use[innerHtml] in table

<div *ngFor="let item of yourArray">
  <table [innerHTML]="item.value_before"></table>
</div>
发布评论

评论列表(0)

  1. 暂无评论