比较来自世界各地的卖家的域名和 IT 服务价格

安全值应使用[属性] =安全旁路后绑定使用 DomSanitizer

HTML CODE
<p #mass_timings=""></p>



//Controller code

@ViewChild/'mass_timings'/ mass_timings: ElementRef;
constructor/private domSanitizer:DomSanitizer/
getInnerHTMLValue//{
this.mass_timings.nativeElement.innerHTML =
this.domSanitizer.bypassSecurityTrustHtml/this.parishDetail.mass_timings/;

}


但是显示的输出 mass_timings, 包括文字: -

安全值应使用[属性] =绑定

在一开始

如何删除此字符串。
已邀请:

小姐请别说爱

赞同来自:

如错误信息所示,纯化 HTML 必须通过绑定属性添加:


<p [innerhtml]="massTimingsHtml"></p>



constructor/private domSanitizer:DomSanitizer/ {
this.massTimingsHtml = this.getInnerHTMLValue//;
}
getInnerHTMLValue//{
return this.domSanitizer.bypassSecurityTrustHtml/this.parishDetail.mass_timings/;
}


https://stackblitz.com/edit/angular-bmxbmy
/基于 Plunker Swapnil 布丁 - 见下面的评论/

江南孤鹜

赞同来自:

你需要 sanitize// safevalue 像这样 :


this.domSanitizer.sanitize/SecurityContext.HTML,this.domSanitizer.bypassSecurityTrustHtml/this.parishDetail.mass_timings//;

裸奔

赞同来自:

使用时收到此错误 iframe, 因此,我纠正了它
[src]

, 如下所示:

导入这一点

:


import { DomSanitizer, SafeHtml } from '@angular/platform-browser';
constructor/private sanitizer: DomSanitizer, ....other DI/{}


在文件中 ts


getSafeUrl// {
return this.sanitizer.bypassSecurityTrustResourceUrl/this.url/;
}


在文件中

html


<iframe *ngif="url" [src]="getSafeUrl//" frameborder="0"></iframe>


这种方法非常耗时,因为它会导致函数好几次,因此可以更好地消毒 URL 里面 lifeCycleHooks, 作为
ngOnInit//

.

您还可以使用管道提高性能:


<div [innerhtml]="htmlValue | byPassSecurity"></div>


import { Pipe, PipeTransform, SecurityContext } from "@angular/core";
import { DomSanitizer, SafeHtml } from '@angular/platform-browser';

@Pipe/{
name: 'byPassSecurity'
}/
export class ByPassSecurityPipe implements PipeTransform {

constructor/private sanitizer: DomSanitizer/ {}

transform /value: string/: SafeHtml {
return this.sanitizer.bypassSecurityTrustHtml/value/;
}
}

莫问

赞同来自:

使用时我会出错 MATHJAX 在 angular 7. 我解决了下面的管道转换问题。 100% 完美跑步

//Sanitize HTML 喇叭


import { Pipe, PipeTransform, SecurityContext } from "@angular/core";
import { DomSanitizer, SafeHtml } from '@angular/platform-browser';

@Pipe/{
name: 'sanitizeHtml'
}/
export class SanitizeHtmlPipe implements PipeTransform {

constructor/private _sanitizer: DomSanitizer/ {
}

transform/value: string/: SafeHtml {
return this._sanitizer.sanitize/SecurityContext.HTML, this._sanitizer.bypassSecurityTrustHtml/value//
}
}

八刀丁二

赞同来自:

我的解决方案使用管道。

HTML


<div [innerhtml]="htmlValue | byPassSecurity"></div>


喇叭


import { Pipe, PipeTransform, SecurityContext } from "@angular/core";
import { DomSanitizer, SafeHtml } from '@angular/platform-browser';

@Pipe/{
name: 'byPassSecurity'
}/
export class ByPassSecurityPipe implements PipeTransform {

constructor/private sanitizer: DomSanitizer/ {}

transform /value: string/: SafeHtml {
return this.sanitizer.bypassSecurityTrustHtml/value/;
}
}

要回复问题请先登录注册