51

I've created a pipe using "ng g pipe" command. I'm getting a console error when I'm using it in my code. The screenshots of the code are attached below. Error: error NG8004: No pipe found with name 'filterByPrcName'. filter-by-prc-name.pipe.tsConsole Error Message product-list.component.html

live-love
  • 48,840
  • 22
  • 240
  • 204
Riyasree
  • 567
  • 1
  • 4
  • 10
  • 9
    You need to add it to the declarations array of the module. If you want to expose it to other modules that import the module it's declared in, you'll also need to add it the exports array. – Jason White Jun 02 '20 at 21:01
  • 1
    Thanks @JasonWhite. I missed to export it. It's working fine now. – Riyasree Jun 02 '20 at 21:29

8 Answers8

86

You will also get this error if your component is not in the declarations array of its parent module.

FunkMonkey33
  • 1,956
  • 2
  • 16
  • 24
  • 9
    Very underrated answer IMHO. This is usually a very hard to catch. – TheZerg Aug 12 '21 at 02:08
  • 3
    This is the truth that everyone needs!!! Go to your modules and add this particular class in the declarations section – Alok Rajasukumaran Sep 23 '21 at 14:31
  • 1
    I occasionally get this error message in VS Code, although my code is correct. I just have to open the `xxx.module.ts` file and the problems go away immediately. Maybe someone else have the same problem...might be a bug which will be fixed in the future. – MikhailRatner Jan 27 '22 at 14:29
  • 1
    Adding to @MikhailRatner - In frustration we often forget to `Ctrl + R` or `F1 -> Reload Window` – Hari Reddy May 17 '22 at 20:00
31

You need to open the angular module that declares your component, then add it to the declarations, and add the needed import.

Example:

 <td>{{product.productCode | lowercase | convertToSpaces: '-' }}</td>

ERROR in src/app/products/product-list.component.html:48:61 - error NG8004: No pipe found with name 'convertToSpaces'.

app.module.ts:

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';

import { FormsModule } from '@angular/forms';

import { AppComponent } from './app.component';
import { ProductListComponent } from './products/product-list.component';
import { ConvertToSpacesPipe } from './shared/convert-to-spaces.pipe'; // <-- Add this

@NgModule({
  declarations: [
    AppComponent,
    ProductListComponent,
    ConvertToSpacesPipe  // <-- Add this
  ],
  imports: [
    BrowserModule,
    FormsModule
  ],
  bootstrap: [AppComponent],

  //exports: [AppComponent],

})
export class AppModule { }

convert-to-spaces.pipe.ts

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

@Pipe({ name: 'convertToSpaces' })

export class ConvertToSpacesPipe implements PipeTransform {

    transform(value: string, character: string): string {
        return value.replace(character, ' ');
    }

}
live-love
  • 48,840
  • 22
  • 240
  • 204
5

I was facing this error when I was using currency pipe in lazy loaded module, for this you have to import CommonModule both in current module and in app.module.ts

For modules which are not lazy loaded no need to import CommonModule

Muhammad Awais
  • 1,608
  • 1
  • 21
  • 21
2

I spent ages trying to solve this problem when modifying code others had implemented, labouring over what I was missing in app.module.ts of if the latest version of Angular had changed things, when finally I discovered that there was another 'module' in the codebase in addition to app.module.ts.

When I finally figured this out and made the code modifications as per @live-love's answer, including pipe declarations in the other module instead of app.module.ts, it finally worked - phew!

Dharman
  • 30,962
  • 25
  • 85
  • 135
Matty J
  • 3,116
  • 32
  • 31
2

In addition to the answers above, if you have the pipe in a SharedModule, make sure you add the pipe in its exports array also

ola357
  • 81
  • 1
  • 2
0

This can happen if you are using the class name of the pipe in the HTML template, instead of using the actual name that was used when the pipe was declared

In my template I was using 'TrustHTMLPipe' instead of 'trustHTML' enter image description here

Mauricio Gracia Gutierrez
  • 10,288
  • 6
  • 68
  • 99
0

If you have built an Angular library (as a multi-project), be sure to add my-thing.module.ts to public-api.ts

Snippet of my public-api.ts

export * from "./my-thing/my-thing.module";  // Don't forget this line!
export * from "./my-thing/my-thing.service";
export * from "./my-thing/list-my-thing/list-my-thing.resolver.service";
export * from "./my-thing/list-my-thing/list-my-thing.component";
...
Adam
  • 2,616
  • 33
  • 29
0

If you imported your pipe into a sharedmodule 's declarations, at first added this module into your current component's module.

Sample:

import { SharedModule } from '@shared/shared.module';

  imports: [
  ...
  SharedModule ,
  ...
]
})
export class SettingsModule { }