zoukankan      html  css  js  c++  java
  • 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

    <div [innerHtml]="content | safeHtml"></div>
  • 相关阅读:
    Door man
    Borg Maze
    Agri-Net
    Highways
    Truck History
    Arctic Network
    QS Network
    用贝塞尔曲线实现水波效果
    在一个Label上设置多种颜色字体
    用UIImageView作出动画效果
  • 原文地址:https://www.cnblogs.com/dawnwill/p/11046332.html
Copyright © 2011-2022 走看看