Angular4 innerHtml呈现富文本内容样式

import { Pipe, PipeTransform } from "@angular/core";
import { DomSanitizer } from '@angular/platform-browser';
 
// https://angular.io/guide/security
@Pipe({ name: 'safeHtml' })
export class SafeHtmlPipe implements PipeTransform {
  constructor(private sanitized: DomSanitizer) { }
 
  transform(value) {
    return this.sanitized.bypassSecurityTrustHtml(value);
  }
}

在app.module.ts配置

import { NgModule } from '@angular/core'
import { SafeHtmlPipe } from '../safe-html.pipe';

import { AppComponent } from './app.component'

@NgModule({
  declarations: [AppComponent, SafeHtmlPipe],
  imports: []
})
export class AppModule {}

在app.component.html

 

转载于:https://www.cnblogs.com/dawnwill/p/11046332.html

你可能感兴趣的:(Angular4 innerHtml呈现富文本内容样式)