4

I am struggling with using a standard angular2 pipe in a non-standard way and I was wondering if there are any ways around it.

Assume I have a variable which its value equals the definition of a standard pipe, for example, the common "date:'medium'" pipe.

let a = "date:\':medium\'";

Now, somewhere in my html, I would like to be able to use this "a" variable the following way:

<p>{{myRecord.date | a}}</p>

And I want this "a" to have the same effect of the date pipe it contains. Is there any way to achieve this?

Behrooz
  • 1,895
  • 4
  • 31
  • 47
  • The arguments are a simple binding like so - https://plnkr.co/edit/HriU12CWbNXncUfq2YIk?p=preview. But the pipe itself you would need to override because it's evaluated. To do that you would just create another pipe and use `DateFormatter.format(Date, locale, pattern);` also importing the - intl.ts. https://github.com/angular/angular/blob/master/packages/common/src/pipes/intl.ts – Dylan May 04 '17 at 17:28
  • @Dylan Link you shared in Dead now – Pardeep Jain May 08 '18 at 09:15
  • Thanks, the plunker seems to have lost a dependency or something, and the github repo for `intl.ts` has also changed. Also `intl` has gone through some changes, refer to https://github.com/angular/angular/pull/18284 – Dylan May 17 '18 at 02:38

0 Answers0