在Angular2 v4中,我有一个包含多个项目的数组。例如:
const array = ['1', '2', '3'];
array.forEach(h => {
this.htmlhistory.concat('hello <br>');
});
htmlhistory
项是一个字符串
在我的 html 组件中,我有这个:
<div>
{{ this.htmlhistory }}
</div>
所以结果必须是:
<div>
hello <br>
hello <br>
hello <br>
</div>
但这行不通...我做错了什么? 有没有不使用*ngFor
的安特斯解决方案?
我需要组件.ts文件中的解决方案...不在 HTML 文件中
请帮忙
而不是
<div>
{{ this.htmlhistory }}
</div>
使用这个
<div [innerHTML]="htmlhistory">
</div>
如果要在组件中呈现HTML,则应使用[innerHTML]="htmlhistory"
而不是{{}}
语法。
这里有一个简单的例子,以防你需要它。