Cannot Instantiate DatePipe

If you take a look at source code then you will see that DatePipe constructor asks for a required parameter: constructor(@Inject(LOCALE_ID) private _locale: string) {} There is no default locale for DataPipe https://github.com/angular/angular/blob/2.0.0/modules/%40angular/common/src/pipes/date_pipe.ts#L97 That’s why typescript gives the error. This way you have to initiate your variable as shown below: datePipeEn: DatePipe = new DatePipe(‘en-US’) … Read more

Dynamic pipe in Angular 2

Building on borislemke’s answer, here’s a solution which does not need eval() and which I find rather clean: dynamic.pipe.ts: import { Injector, Pipe, PipeTransform } from ‘@angular/core’; @Pipe({ name: ‘dynamicPipe’ }) export class DynamicPipe implements PipeTransform { public constructor(private injector: Injector) { } transform(value: any, pipeToken: any, pipeArgs: any[]): any { if (!pipeToken) { return … Read more

How do I call an Angular 2 pipe with multiple arguments?

In your component’s template you can use multiple arguments by separating them with colons: {{ myData | myPipe: ‘arg1′:’arg2’:’arg3’… }} From your code it will look like this: new MyPipe().transform(myData, arg1, arg2, arg3) And in your transform function inside your pipe you can use the arguments like this: export class MyPipe implements PipeTransform { // … Read more