要绘制的 Typescript concat 字符串 Html

Typescript concat string to draw 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 文件中

请帮忙

如果您想在您的组件中呈现 HTML,您应该使用 [innerHTML]="htmlhistory" 而不是 {{}} 语法。

这是一个快速 example,以备不时之需。

而不是

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

使用这个

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