typescript Angular 5安全html管道
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了typescript Angular 5安全html管道相关的知识,希望对你有一定的参考价值。
**Inside tag:** `<iframe width="560" height="315" [src]="getVideoURL(video.embed) | safe"></iframe>`
**Interpolation:** `{{ getVideoURL(video.embed) | safe }}`
**Note:** Pipe can be generate using angular cli: *ng g pipe path/name*
import { Pipe, PipeTransform } from '@angular/core';
import { DomSanitizer } from '@angular/platform-browser';
@Pipe({
name: 'safe'
})
export class SafePipe implements PipeTransform {
constructor(private sanitizer: DomSanitizer) { }
transform(value: any, args?: any): any {
if (value) {
return this.sanitizer.bypassSecurityTrustResourceUrl(value);
}
}
}
以上是关于typescript Angular 5安全html管道的主要内容,如果未能解决你的问题,请参考以下文章