I want to use the datePipe in my component. I followed the instructions here but I am met with
Error: StaticInjectorError[DatePipe]:
StaticInjectorError[DatePipe]:
NullInjectorError: No provider for DatePipe!
Here is my code:
Component
import { DatePipe } from '@angular/common';
export class LivePreviewComponent implements OnInit{
currentDate = new Date();
constructor(private datePipe:DatePipe) {}
ngOnInit() {
this.datePipe.transform(this.currentDate, 'YYYY-MM-DDTHH:mm')
}
}
Add in the Module
providers: [DatePipe],
Add in the constructor
private datePipe: DatePipe
Add in Ts file for Form Array:
Pipes, unlike Services, are not injectable. In order to use pipe in a component, you need to create new instance of it:
Add to providers array in the component
or inject it to module
or write a separate class extending the DatePipe and use it as a service
and inject this to providers array