I want to use 'date' pipe, but I don't want to use it inside HTML template, but inside a Typescript function, something like:
dateString.filter(date)
Do you have an idea how to do it?
You should inject DatePipe inside providers array of your NgModule first (As injectables should have been registered in providers array) and then you can use DatePipe inside your application as injector. You have to call its transform function to format date. Inject DatePipe it inside constructor of your component before using it DatePipe
@NgModule({
imports: [..],
declarations: [..],
providers: [ DatePipe, ..], //this is very much important line.
bootstrap: [AppComponent]
})
export class AppComponent {
}
Usage
//just for demo, I put filter inside constructor
constructor(private datePipe: DatePipe){ datePipe.tranform(date); }