zoukankan      html  css  js  c++  java
  • angular->html文本显示

    1.新建pipe 文件

    import {Pipe, PipeTransform} from '@angular/core';
    import {DomSanitizer} from '@angular/platform-browser';
    
    @Pipe({
      name: 'htmlReset'
    })
    export class HtmlResetPipe implements PipeTransform {
    
      constructor(private domSanitizer: DomSanitizer) {
    
      }
    
      transform(style) {
        return this.domSanitizer.bypassSecurityTrustHtml(style);
      }
    
    }
    View Code

    2.新建module

    import {NgModule} from '@angular/core';
    import {CommonModule} from '@angular/common';
    import {FileSizeFormatPipe} from '../../pipes/file-size-format.pipe';
    import {HtmlResetPipe} from '../../pipes/html-reset.pipe';
    
    @NgModule({
      declarations: [FileSizeFormatPipe, HtmlResetPipe],
      imports: [
        CommonModule
      ],
      exports: [FileSizeFormatPipe, HtmlResetPipe]
    })
    export class CommonPipeModule {
    }
    View Code

    3.在需用此管道的module中引入该module

    import {NgModule} from '@angular/core';
    import {CommonModule} from '@angular/common';
    
    import {ShareInfoRoutingModule} from './share-info-routing.module';
    import {ShareInfoComponent} from './share-info.component';
    import {NgZorroAntdModule} from 'ng-zorro-antd';
    import {FormsModule, ReactiveFormsModule} from '@angular/forms';
    import {CommonPipeModule} from '../../common/modules/common-pipe/common-pipe.module';
    import {TranslateModule} from '@ngx-translate/core';
    import {MainModule} from '../main/main.module';
    
    
    @NgModule({
      declarations: [ShareInfoComponent],
      imports: [
        CommonModule,
        ShareInfoRoutingModule,
        NgZorroAntdModule,
        FormsModule,
        ReactiveFormsModule,
        CommonPipeModule, // 管道module
        MainModule,
        TranslateModule.forChild(),
      ]
    })
    export class ShareInfoModule {
    }
    View Code

    4.在界面上调用

     <div class="content" [innerHTML]="msgInfoData?.Content|htmlReset"></div>
  • 相关阅读:
    [收藏转贴]struct探索·extern "C"含义探索 ·C++与C的混合编程·C 语言高效编程的几招
    [收藏转贴]构建RESTful风格的WCF服务
    [转贴] C/C++中动态链接库的创建和调用
    [转贴]WebService的简单实现 C++
    谷歌已经对Android的开源严防死守
    如何成为一名黑客?
    当程序员思路被打断
    编辑语言是这样的
    开发者需要掌握多少门语言?
    程序员的六大优势
  • 原文地址:https://www.cnblogs.com/huangmin1992/p/12401020.html
Copyright © 2011-2022 走看看