I'm having a problem creating a custom Pipe.
I created the following module (pipes.module.ts):
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { CnpjPipe } from './cnpj.pipe';
@NgModule({
imports: [
CommonModule
],
declarations:
[
CnpjPipe
],
exports:
[
CnpjPipe
],
})
export class PipesModule {
static forRoot() {
return {
ngModule: PipesModule,
providers: [],
};
}
}
This is my Pipe that was created:
import { Pipe, PipeTransform } from '@angular/core';
@Pipe({
name: 'cnpj'
})
export class CnpjPipe implements PipeTransform {
transform(value: any, args?: any): any {
return '${value.substr(0, 2)}.${value.substr(2, 3)}.${value.substr(5, 3)}/${value.substr(8, 4)}-${value.substr(12, 2)}';
}
}
I made the import of this module into my app.module.ts:
import { PipesModule } from './pipes/pipes.module';
declarations: [
...
],
imports: [
...,
PipesModule.forRoot()
],
At the time of using Pipe in this way:
<div class="col-md-2 text-left">
{{ objUsuario.cnpj | cnpj }}
</div>
Give the following error:
**
The pipe 'cnpj' could not be found
**