angular - 打字稿连接字符串来绘制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 文件中
请帮忙
解决方案
代替
<div>
{{ this.htmlhistory }}
</div>
用这个
<div [innerHTML]="htmlhistory">
</div>
推荐阅读
- firebase - 如何在像 firestore 这样的 nosql 解决方案中创建多租户数据模型?
- sql - 层次名称的 SQL 递归查询
- javascript - 为什么 canvas.toBlob 和 canvas.toDataURL 有不同的返回类型
- reactjs - How can I communicate between two react sibling component directly without using parent component?
- markdown - 使用 pandoc 的大都会主题突出问题
- ruby-on-rails - Rails 5检查belongs_to关系中是否存在记录?
- php - 显示 SQL 表行中的数组值
- css - YouTube 视频 iframe 上的 4 个圆角
- github - 警告:无法从“http://gems.github.com”中提取数据:未找到错误响应 404 (http://gems.github.io/specs.4.8.gz)
- sql-server - How can I execute "for json path" in dqe and insert result of execute in temp table in SQL Server?