[英]How to add a html element to Value in Array JSON, Typescript, Angular
I want to add some Dynamic data to my Angular Project, I have a JSON file which has the Data and, I am fetching it from typescript and using it in my html. I want to add some Dynamic data to my Angular Project, I have a JSON file which has the Data and, I am fetching it from typescript and using it in my html. I want to store a HTML element in a value and then use it in my html so, I did it and it just shows me the HTML element in the result, like:
我想将 HTML 元素存储在一个值中,然后在我的 html 中使用它,所以我做到了,它只是在结果中显示了 HTML 元素,例如:
If i write如果我写
[
{
"element": "<h1>Element<h1>"
}
]
Then the result in browser is:然后浏览器中的结果是:
<h1>Element<h1>
Instead of showing a h1
Element而不是显示一个
h1
元素
Will appreciate a answer!将不胜感激!
Try innerHtml试试innerHtml
<div *ngFor="let li of list">
<div [innerHTML]="li.elem"></div>
</div>
ts ts
list = [{
elem: "<h3>Hello</h3>"
}, {
elem: "<h3>World</h3>"
}];
example: https://stackblitz.com/edit/angular-ivy-qbg51b?file=src%2Fapp%2Fapp.component.ts例如: https://stackblitz.com/edit/angular-ivy-qbg51b?file=src%2Fapp%2Fapp.component.ts
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.