This commit is contained in:
Taric Xin
2021-12-27 18:27:08 +08:00
parent 7e6d86d00e
commit 786c2e1bad
13 changed files with 104 additions and 84 deletions

View File

@ -0,0 +1,2 @@
export * from './pipe.module';
export * from './trushtml.pipe';

View File

@ -0,0 +1,10 @@
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { TrushtmlPipe } from './trushtml.pipe';
@NgModule({
declarations: [TrushtmlPipe],
imports: [CommonModule],
exports: [TrushtmlPipe]
})
export class PipeModule {}

View File

@ -0,0 +1,29 @@
/*
* @Description:
* @Author: wsm
* @Date: 2021-06-23 17:02:20
* @LastEditTime: 2021-06-23 17:04:57
* @LastEditors: wsm
* @Reference:
*/
import { Pipe, PipeTransform } from '@angular/core';
import { DomSanitizer } from '@angular/platform-browser';
@Pipe({
name: 'safehtml',
})
export class TrushtmlPipe implements PipeTransform {
constructor(private sanitizer: DomSanitizer) {}
transform(value: any, args?: any): any {
try {
if (!value || value === '') {
return '';
}
return this.sanitizer.bypassSecurityTrustHtml(value);
} catch (e) {
console.warn(e);
return '';
}
}
}