问题
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>
回答1:
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
回答2:
This works:
en.json
'DETAIL': 'Liability {{id}} - from {{date}}'
template
{{ 'DETAIL' | translate: { id: id, date: lastModifiedDate | date: 'medium' } }}
来源:https://stackoverflow.com/questions/38355577/pipe-with-piped-parameter-in-angular-2