具有角度2的管道参数的管道 [英] Pipe with piped parameter in angular 2

查看:77
本文介绍了具有角度2的管道参数的管道的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想写些类似的东西

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

其中translate ng2-translate 的管道函数.

我想显示:今天是2016年7月13日",所以CURRENT_DATE"Today is {{value}}"并需要一个动态值.

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

根据用户的语言环境,当前日期格式会更改.我有一个函数getDateFormat,它返回"yy-MM-dd""dd/MM/yy".

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 ?

谢谢!

编辑:好的,我太愚蠢了,无法复制没有错误的示例. 我应该写过:

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>

推荐答案

为什么不做类似的事情:

Why not do something like:

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

然后getDate()函数使用以下信息的组合在所需的语言环境中创建日期:

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的管道参数的管道的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆