7

I want to use the DatePipe in HTML

{{ timeslot | date }}

but I get the error

error NG8004: No pipe found with name 'date'

My app.module.ts imports the common module

import { CommonModule } from '@angular/common';

@NgModule({
  imports: [
     CommonModule,
  ],
  declarations: [],
}

What I am doing wrong?

Jake
  • 11,273
  • 21
  • 90
  • 147
  • Does this answer your question? [Angular - No pipe found with name](https://stackoverflow.com/questions/62161219/angular-no-pipe-found-with-name) – Deepak A Sep 08 '21 at 09:58

3 Answers3

7

Try to put your component in declarations like:

import { CommonModule } from '@angular/common';

@NgModule({
  imports: [
     CommonModule,
  ],
  declarations: [YourComponent],
}
Georges Feungap
  • 456
  • 3
  • 8
7

All I want to do is use Angular pipe in HTML.

{{ timeslot | date }}

I spent 2 hours on this issue troubleshooting and Google searching the error message,

error NG8004: No pipe found with name 'date'.

only to get the same repeated advice for adding CommonModule to imports, or adding to providers then inject into the Component and Service files.

To help those who made the same silly mistake as I did, please check you have added your component into the app.module.ts declarations first. You don't even need to do any thing else (import CommonModule whatsoever) to use Angular pipes.

Jake
  • 11,273
  • 21
  • 90
  • 147
1

For larger, more complex apps, make sure the whole dependency tree is correctly imported.

I suffered this error because a piece was missing in a parent module file. Specifically, the component with the error did not have its declaring module imported into the main app module. Everything else was correct: imported the CommonModule from Angular (for the date pipe), declared the erring module in its own module, exported the erring module from its own module.

Zarepheth
  • 2,465
  • 2
  • 32
  • 49
  • This happened to me. I removed a component and the connected module was not compile. All I had to do was remove the reference to the deleted component in the module and everything built – Ben Anderson Mar 31 '23 at 15:43