应将代码插入相应的div
ngOnInit() {
if (this.pageOrSlug) {
this._pageSubscriver = this._pageService.getByIdOrSlug(this.pageOrSlug).subscribe((page: IPage) => {
this.title = page.title;
this.body = this._sanitizer.bypassSecurityTrustHtml(page.body['en']);
});
}
}
模板
<ng-container *ngIf="title">
<h1 [innerHTML]="title['en']"></h1>
<div [innerHTML]="body"></div>
一切正常,除了一个 如果在html代码中找到了自定义组件,则不会对其进行处理
For Example if body = '<fa-icon></fa-icon>'