angularjs filter 'date' and $locale service

后端 未结 2 399
有刺的猬
有刺的猬 2021-01-17 11:13

it seems that angularjs embed some internationalized resources:

Angular supports i18n/l10n for date, number and currency filters. Additionally, Angu

2条回答
  •  失恋的感觉
    2021-01-17 11:50

    Example of use, as per https://docs.angularjs.org/guide/i18n

    1) get the locale you need from the angular repo or through bower, e.g. //raw.githubusercontent.com/angular/bower-angular-i18n/master/angular-locale_fr-fr.js

    2) include it after the angular library, e.g.

    
    
    

    3) now whenever you display a date using the ng date filter, it will be in French-France, not US English format, e.g.

    {{date | date: 'fullDate'}}
    

    There's also gotta be a way to handle several locals programmatically, it's done on the AngularJS home page "beer counter" example, with

    angular.module('app-us', ['app', 'ngLocal.us']);
    angular.module('app-sk', ['app', 'ngLocal.sk']);
    

    and

    
    
    
    
    

    And here's a cleaner way to do it: https://github.com/lgalfaso/angular-dynamic-locale

提交回复
热议问题