angular富文本解析,内置样式不生效问题
程序员文章站
2022-06-07 14:07:57
...
1.新建管道 pipe/htmlpipi.pipe.ts文件
import { Pipe, PipeTransform } from '@angular/core';
import { DomSanitizer } from "@angular/platform-browser";
@Pipe({
name: 'htmlpipe'
})
export class HtmlpipePipe implements PipeTransform {
constructor(private sanitizer: DomSanitizer) {
}
transform(style) {
return this.sanitizer.bypassSecurityTrustHtml(style);
}
}
2.在公共文件modules/share/share.module.ts文件引入
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { DebounceClickDirective } from '../../directives/debounce-click.directive';
import { HtmlpipePipe } from '../../pipe/htmlpipe.pipe';
@NgModule({
declarations: [
DebounceClickDirective,
HtmlpipePipe
],
imports: [
CommonModule
],
exports: [
DebounceClickDirective,
HtmlpipePipe
]
})
export class ShareModule { }
3.在使用页面引入
// 防抖指令
import { ShareModule } from '../../modules/share/share.module';
imports: [
ShareModule
],
4.在页面使用
<ion-content>
<h5 [innerHTML]="newsdetail.title"></h5>
<div class="content" [innerHTML]="newsdetail.content | htmlpipe"></div>
</ion-content>
上一篇: 一次场景模拟/go实现
下一篇: 一个只有在精神病院住过的人才能想到的写法