imsi imsi imsi imsi - 1 year ago 90
AngularJS Question

Error converting month number to month name in angularjs

i used this filter to convert month number to month name and its works fine :

.filter('monthName', [function() {
return function (monthNumber) { //1 = January
var monthNames = [ 'January', 'February', 'March', 'April', 'May', 'June',
'July', 'August', 'September', 'October', 'November', 'December' ];
return monthNames[monthNumber - 1];



<canvas id="line" class="chart chart-line" chart-data="dataf"
chart-labels={{labelsf | monthName}} chart-series="seriesf" chart-options="options"
chart-dataset-override="datasetOverride" chart-click="onClick">

but it gives me this error:

ionic.bundle.js:26794 Error: [$parse:syntax] Syntax Error: Token '{' invalid key at column 2 of the expression [{{labelsf] starting at [{labelsf].

can anybody please tell me what is the error, can anybody tell how i can apply this filter in js code instead of in the view??

Answer Source

I recommend to you to use the $locale service as a DI, using specifically the $locale.DATETIME_FORMATS.MONTH array.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download