amedeiros
amedeiros

Reputation: 167

Angular 5 not able to find custom pipe

Everywhere I can find says that you only need to declare it in the module file what am I missing? If anyone needs more information I can add whatever is needed

Pipe file:

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

@Pipe({
  name: 'partnersearch'
})
export class PartnerPipe implements PipeTransform {

    transform(value: any, args?: any): any {
        if (value.startsWith("::ffff:")) value = value.slice(7);
        return value;
    }

}

module.ts file (they are in the same folder):

import { PartnerPipe } from './partner.pipe';

@NgModule({
imports: [],
declarations: [
    PartnerPipe
]})

html:

{{ partner | partnersearch }}

Upvotes: 2

Views: 1191

Answers (2)

Ulrich Dohou
Ulrich Dohou

Reputation: 1559

You should also export it if it is in a shared module.

import { PartnerPipe } from './partner.pipe';

@NgModule({
  declarations: [
    PartnerPipe 
  ],
  exports: [
    PartnerPipe
  ]
})   

Upvotes: 3

Teddy Sterne
Teddy Sterne

Reputation: 14201

You need to declare it in the module so that the components can use it.

import { NgModule } from '@angular/core';
import { PartnerPipe } from './partner.pipe';

@NgModule({
  declarations: [PartnerPipe],
})
export class MyModule {}

Upvotes: 2

Related Questions