代码之家  ›  专栏  ›  技术社区  ›  Samir Guiderk

以角度6解码HTML实体

  •  1
  • Samir Guiderk  · 技术社区  · 8 年前

    我在找一个可以用角度6解码HTML实体的库。

    我试图找到一些东西,我在角2中找到了一个叫做trustashtml的函数, 但我认为6版没有。

    下面您可以在HTML模板中找到我的代码:

     <div [innerHTML]="post.body | markdown"></div>
    

    我的field post api返回本机HTML如下:

    <p style="margin: 1em 0px; font-size: 18px; line-height: 1.5; font-family: Lato, sans-serif;">Hey Android users! Since launching the Grammarly Keyboard for iOS, we&rsquo;ve heard from </p>
    

    知道吗?

    1 回复  |  直到 8 年前
        1
  •  2
  •   ElasticCode    8 年前

    DomSanitizer bypassSecurityTrustHtml() style

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

    <div [innerHtml]="html | safeHtml"></div>
    

    html: string = "<p style='margin: 1em 0px; font-size: 18px; line-height: 1.5; font-family: Lato, sans-serif;'>Hey Android users! Since launching the Grammarly Keyboard for iOS, we&rsquo;ve heard from </p>";
    
    推荐文章