Jace Rhea
Jace Rhea

Reputation: 5018

How to get the localized version of the months from angularjs?

How would I get a localized version of every month in angularjs in an array? I know how to localize a single date using the format options, but in this case I want all of the months. Basically, this is going to be bound to a select that the user can than choose a month.

Upvotes: 4

Views: 7985

Answers (1)

Nicolas ABRIC
Nicolas ABRIC

Reputation: 4935

I m guessing that your page will be entirely localized in a given language and that you will add the proper angular-locale file as such :

<script src="http://.../angular-locale_xx-xx.js"></script> // ex: angular-locale_fr-fr.js

If this is the case you can simply access all the months as an array like that :

function Controller($scope, $locale) { //inject the $locale service
  var datetime = $locale.DATETIME_FORMATS; //get date and time formats 
  $scope.months = datetime.MONTH; //access localized months
}

You can see a working plunker here

Upvotes: 14

Related Questions