I'm not using pipes for the first time, but now I'm trying to use safe pipe which I created in a separated folder "pipes" with PipesModule
as below
this is the pipe class:
safe.pipe.ts
import { Pipe, PipeTransform } from '@angular/core';
import { DomSanitizer, SafeHtml, SafeResourceUrl, SafeScript, SafeStyle, SafeUrl } from '@angular/platform-browser';
@Pipe( {
name: 'safe'
} )
export class SafePipe implements PipeTransform {
constructor ( protected sanitizer: DomSanitizer ) { }
public transform ( url: any ) {
return this.sanitizer.bypassSecurityTrustResourceUrl( url );
}
}
and this is the module file pipes.module.ts
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { SafePipe } from './safe.pipe';
@NgModule( {
declarations: [
SafePipe
],
exports: [
SafePipe
],
imports: [
CommonModule
]
} )
export class PipesModule { }
and I imported the PipesModule in the component module that I want to use pipe in,
@NgModule( {
declarations: [ GenerateContractComponent ],
imports: [
CommonModule,
FormsModule,
NgxMaskModule,
PipesModule
]
} )
Then used pipe in HTML as this:
<iframe width="100%" style="height:-webkit-fill-available" [src]="pdfURL | safe" frameborder="0"></iframe>
but still get the error
Error: Uncaught (in promise): Error: NG0302: The pipe 'safe' could not be found!
Please can anyone help??
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…