2
I’m having a problem creating a custom Pipe.
I created the following module (Pipes.modulets.):
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 imported this module into my app.module.ts:
import { PipesModule } from './pipes/pipes.module';
declarations: [
...
],
imports: [
...,
PipesModule.forRoot()
],
When it comes to using PIPE in this way:
<div class="col-md-2 text-left">
{{ objUsuario.cnpj | cnpj }}
</div>
From the following error:
**
The pipe 'cnpj' could not be found
**
This may sound stupid, but you’re already trying to change the order of the Imports array? To me it happens a few times that X import is not well done and I pass it to a few Indexes before and import works :|
– MoshMage