Angular 6 innerHTML添加自定义指令

时间:2018-10-24 16:57:44

标签: angular components innerhtml

应将代码插入相应的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>'

0 个答案:

没有答案