首页 > 解决方案 > 打字稿连接字符串来绘制Html

问题描述

在 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

我需要在 component.ts 文件中的解决方案...而不是在 html 文件中

请帮忙

标签: angularstringtypescriptconcat

解决方案


代替

<div>
  {{ this.htmlhistory }}
</div>

用这个

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

推荐阅读