I want to use a custom pipe in all of my components, according to the internet i should use a Shared module in which i import/export the pipe. When i import the shared module in the components in which i want to use the pipe it is supposed to work, but not for me.
The Pipe: import { Pipe, PipeTransform } from '@angular/core';
@Pipe({
name: 'empty'
})
export class EmptyPipe implements PipeTransform {
public transform(value: any, ...args: any[]): string {
if (!value || value.length < 1) {
if (args.length < 1) {
return "-"
} else {
return args[0];
}
}
return value;
}
}
The Shared Module:
import { CommonModule } from '@angular/common';
import { NgModule} from '@angular/core';
import { EmptyPipe } from './pipes/empty.pipe';
@NgModule({
imports: [CommonModule],
declarations: [EmptyPipe],
exports: [EmptyPipe, CommonModule]
})
export class SharedModule {
}
How I import it in the component i want to use it in:
import { SharedModule } from '../shared/shared.module';
How I try to use it:
{{companyList.earliest | empty}}
The error:
The pipe 'empty' could not be found