4

I'd like to write something like

<p>{{"CURRENT_DATE" | translate:(value:(currentDate | date:getDateFormat))}}</p>

where translate is a pipe function from ng2-translate.

I'd like to display: "Today is 2016-07-13", so CURRENT_DATE is "Today is {{value}}" and expects a dynamic value.

Depending on the user's locale, the current date format changes. I have a function getDateFormat which returns "yy-MM-dd" or "dd/MM/yy".

I know it is possible to chain pipes, but my case here is not really chaining pipes.

Is there a simple way, or do I have to write a custom pipe ?

Thanks !

EDIT: Okay my bad, I was too dumb to copy the example without errors. I should have written :

<p>{{"CURRENT_DATE" | translate:{value:currentDate | date:getDateFormat } }}</p>
Maciej Treder
  • 11,866
  • 5
  • 51
  • 74
Gnujeremie
  • 570
  • 3
  • 17

2 Answers2

2

Why not do something like:

<p>{{"CURRENT_DATE" | translate:{value: getDate()}}}</p>

And then getDate() function creates the date in the locale required using a combination of the information here: https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleDateString

Maximilian Riegler
  • 22,720
  • 4
  • 62
  • 71
0

This works:

  • en.json

    'DETAIL': 'Liability {{id}} - from {{date}}'

  • template

    {{ 'DETAIL' | translate: { id: id, date: lastModifiedDate | date: 'medium' } }}

Felix
  • 3,999
  • 3
  • 42
  • 66