Quantcast
Channel: Ionic Forum - Latest posts
Viewing all articles
Browse latest Browse all 230429

Pipe could not be found in ionic4

$
0
0

To solve this I had to create all my new custom pipes inside a folder called “pipes”, then I created a module called “sharedPipe.module.ts” inside a folder “modules”

/modules/sharePipe.module.ts

import {NgModule} from '@angular/core';
import {CommonModule} from '@angular/common';
import {CpfPipe} from '../pipes/cpf.pipe';

@NgModule({
    declarations: [CpfPipe],
    imports: [
        CommonModule
    ],
    exports: [
        CpfPipe
    ]
})
export class SharedPipeModule {}

/pipes/cpf.pipe.ts

import {Pipe, PipeTransform} from '@angular/core';

@Pipe({
    name: 'cpf'
})
export class CpfPipe implements PipeTransform {

    transform(value: any): any {
        if (value == '' || value == null || value == undefined) {
            return value;
        }

        return value.replace(/(\d+)(\d{3})(\d{3})(\d{2})/, " $1.$2.$3-$4");
    }
}

/pipes/cpf.pipe.spec.ts

import {CpfPipe} from './cpf.pipe';

describe('CpfPipe', () => {
    it('create an instance', () => {
        const pipe = new CpfPipe();
        expect(pipe).toBeTruthy();
    });
});

Then I only include my SharedPipeModule inside the modules that will use it.


Viewing all articles
Browse latest Browse all 230429

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>