Angular 未正确渲染动态创建的mat复选框
我根据API获取的传入数据动态创建Angular 未正确渲染动态创建的mat复选框,angular,angular-material,Angular,Angular Material,我根据API获取的传入数据动态创建元素 组件1.ts: this.content = sanitizer.bypassSecurityTrustHtml(`<mat-checkbox>test</mat-checkbox>`) this.content=sanitizer.bypassSecurityTrustHtml(`test`) component.html <div [innerHTML]="content"></div> 但是没
元素
组件1.ts:
this.content = sanitizer.bypassSecurityTrustHtml(`<mat-checkbox>test</mat-checkbox>`)
this.content=sanitizer.bypassSecurityTrustHtml(`test`)
component.html
<div [innerHTML]="content"></div>
但是没有呈现复选框输入,如果我使用
而不是`
如果我添加了“Angular不会处理动态添加的HTML,它只会逐字添加,除了一些防止安全问题的清理之外。”[参见Stackoverflow问题]
要了解如何动态添加角度组件,请参见以下内容:
但我有一些数据(对象)不是组件,我想将它们注入当前组件中@克里斯托弗·佩斯特