我想在 HTML 中动态添加以下内容。
<ng-template #elseblock *ngIf="var">
<h1>
{{heading}}
</h1>
</ng-template>
我为此使用以下方法。
在 app.component.ts 文件中:
htmldata: any = `<ng-template #elseComponent *ngIf="var">
<h1>
{{ heading }}
</h1>
`;
并在 app.component.html
<div [innerHTML]="htmldata"> </div>
但是这个方法只在 DOM 中渲染 h1 标签。(没有 ng-template)
请帮助我动态添加 ng-template,以便 #else 块,*ngIf 也可以工作。