1

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.

4
  • Note that the HTML in there is malformed (</td>td> - typo?) and incomplete (part of a HTML table). Commented Jun 18, 2019 at 6:05
  • you have typing mistakes near less_then</td>. unopened td tag. and missing closing tr tag Commented Jun 18, 2019 at 6:06
  • Yes, It is there. Commented Jun 18, 2019 at 6:07
  • Possible duplicate of Angular2 - Interpolate string with html Commented Jun 18, 2019 at 7:29

3 Answers 3

5

you should use [innerHTML] directive that comes 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>
Sign up to request clarification or add additional context in comments.

2 Comments

is it possible to give style to the array object and it will render at the front?
it is, you can have it as object that would follow up [ngStyle] directive like [ngStyle]="{'color': '#fff'}". This means that you could have in you object property style and have new object in it as style: {'color': '#fff'} so you can use it in your template like <div [innerHTML]="item.value_before" [ngStyle]="item.style"></div>. Hope that i explained it right, if not let me know in private or write a new question on stackoverflow.
2

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

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

Comments

0

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>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.