Pipe not found - Angular 5

2

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

**

    
asked by anonymous 26.04.2018 / 14:31

1 answer

1

I solved the problem, it happened that I was using Pipe inside a component inside a shared module.

And my Pipe module was being called in a single application module.

So the component inside the shared module could not find the Pipe that was imported inside a single module.

    
27.04.2018 / 18:51