我想动态地在我的html代码中放置一个html代码,所以我写下面的代码:
<ng-container [innerHTML]="buttonIcon"></ng-container>
Angular说 innerHTML 不是 ng-container 的有效属性我不想使用如下的第三个html标签:
innerHTML
ng-container
<div [innerHTML]="buttonIcon"></div>
那么如何在没有任何标签内部html绑定的情况下插入html代码呢?
ng-container 没有渲染到html,它只是structural directive .
Angular是一个不会干扰样式或布局的分组元素,因为Angular不会将它放在DOM中 .
所以没有把html放入的元素 . 你需要使用sub-div . 如果您认为不需要sub-div,那么您很可能也只是将 ng-container 替换为 div 本身并且根本不使用容器 .
div
你可以使用ngTemplate:
<ng-template #buttonIcon> <div> Your html</div> </ng-template> <ng-container *ngTemplateOutlet="buttonIcon"> </ng-container>
2 回答
ng-container
没有渲染到html,它只是structural directive .所以没有把html放入的元素 . 你需要使用sub-div . 如果您认为不需要sub-div,那么您很可能也只是将
ng-container
替换为div
本身并且根本不使用容器 .你可以使用ngTemplate: