edit
This commit is contained in:
2
src/app/shared/pipes/index.ts
Normal file
2
src/app/shared/pipes/index.ts
Normal file
@ -0,0 +1,2 @@
|
||||
export * from './pipe.module';
|
||||
export * from './trushtml.pipe';
|
||||
10
src/app/shared/pipes/pipe.module.ts
Normal file
10
src/app/shared/pipes/pipe.module.ts
Normal 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 {}
|
||||
29
src/app/shared/pipes/trushtml.pipe.ts
Normal file
29
src/app/shared/pipes/trushtml.pipe.ts
Normal 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 '';
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user