【发布时间】:2019-12-20 08:01:11
【问题描述】:
我有一些 api 数据..Json 格式的 HTML 标记:
[
{
type: 'p',
attributes: [...],
children: [{...},{...}]
}
]
我想在一个角度模板中呈现它。 由于标签的名称来自api,我需要插入标签名称。
我试过这个:
<ng-container *ngFor="let el of body">
<{{el.type}}> foo bar</{{el.type}}>
</ng-container>
但得到“意外的结束标记“{{el.type}}”。
预期输出:
<p> foobar</p>
而且我不想使用 innerHtml 指令。
【问题讨论】:
-
它是一个对象数组。尝试 {{el[0].type}} 获取第一种类型的 el 对象
-
更新了 sn-p。我已经在对象级别了。
-
我想使用 type 属性作为 html 标签
-
你为什么不想使用
[innerHTML]?我知道一个可能的原因,但我想知道你的原因是什么......