AngularJS translate: Format dynamic dates

不羁岁月 提交于 2019-11-29 10:02:51

Assuming you have following angular-translate translations definitions:

//de    
"with_date": "German: {{date|date:'short'}}"

//en    
"with_date": "English: {{date|date:'medium'}}"

Then inside a view you can do:

<h1>{{ 'with_date'|translate:{date:today} }}</h1>

Where today is defined in controller i.e.:

$scope.today = new Date();

Assuming you've loaded angular-locale_* with correct locale the dates will be formatted in a language/country specific way.

Here's a demo.

Having said that localization mechanism built into angular (ngLocale) is very limited and when it comes to dates you can accomplish wonders with moment.js

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!