[英]Apply filter on filter arguments
I am using angular-translate and need to make date/time localization. 我正在使用angular-translate,并且需要进行日期/时间本地化。
Therefore I need to apply time format filters (angular-moment) on filter arguments for the angular-translate filter which does variable replacement. 因此,我需要在执行变量替换的angular-translate过滤器的参数上应用时间格式过滤器(angular-moment)。
But this should be a general issue/use case independent of angular-translate and angular-moment. 但这应该是一个独立于角度平移和角度矩的一般问题/使用案例。
Without the argument filtering it works (but then i have no localised time format): 没有参数过滤它的作品(但后来我没有本地化的时间格式):
<div data-ng-repeat="msg in data.messages">;
{{msg.text | translate:{timestamp: msg.timestamp } }}
</div>
Doesn't work: 不起作用:
<div data-ng-repeat="msg in data.messages">
{{msg.text | translate:{timestamp: msg.timestamp | amDateFormat:'LT'} }}
</div>
is producing a syntax error: 正在产生语法错误:
Error: [$parse:syntax] Syntax Error: Token '|' is unexpected, expecting [}] at column 73 of the expression [msg.text | translate:{timestamp: msg.timestamp | amDateFormat:'LT' } ] starting at [| amDateFormat:'LT' } ].
http://errors.angularjs.org/1.2.15/$parse/syntax?
2nd guess also doesn't work: 第二个猜测也不起作用:
<div data-ng-repeat="msg in data.messages">
{{msg.text | translate:{timestamp: {msg.timestamp | amDateFormat:'LT'} } }}
</div>
is producing a syntax error: 正在产生语法错误:
Error: [$parse:syntax] Syntax Error: Token '|' is unexpected, expecting [}] at column 74 of the expression [msg.text | translate:{timestamp: {msg.timestamp | amDateFormat:'LT'} } ] starting at [| amDateFormat:'LT' } } ].
http://errors.angularjs.org/1.2.15/$parse/syntax?
I am using AngularJS 1.2.15. 我正在使用AngularJS 1.2.15。
For future reference - you need to add parentheses around the expression, like so: 供将来参考-您需要在表达式周围添加括号,如下所示:
<div data-ng-repeat="msg in data.messages">
{{msg.text | translate:{ timestamp: (msg.timestamp | amDateFormat:'LT') } }}
</div>
This being the relevant part: (msg.timestamp | amDateFormat:'LT')
这是相关的部分:
(msg.timestamp | amDateFormat:'LT')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.