I
I
Ivan-P2016-04-19 01:23:12
JavaScript
Ivan-P, 2016-04-19 01:23:12

Why is the Angular component not working?

There is a Service:

import matrix from '../customCalendarMatrix/calendarMatrix';

export default class calendarService {
    getCalendar(period ,startDate) {

        let periodSize = period || 3;
        let start = startDate || new Date;
        let today = {
            year: start.getFullYear(),
            month: start.getMonth()
        };

        console.log(today.month);

        let _period = [];


        _period['y'+today.year] = {};

        for(let i = 0; i < periodSize; i++) {

            let subperiod = {};



            if(today.month <= 10) {
                today.month++;
            }else {
                today.year++;
                _period['y'+today.year] = {};
                today.month = 0;
            }
            
            _period['y'+today.year]['m'+today.month] = matrix(today.year, today.month);

        };
        console.log(_period);
        return _period;
        
    }

};

there is a Component:
export default function(){

  return {
    template: require('./calendar.cmp.html'),
    controller: CalendarComponent
  }

};

class CalendarComponent {

  constructor(calendarService) {
    this.calendarService = calendarService;
    this.activate();
  };

  activate() {
    this.calendar = this.calendarService.getCalendar(12);
    console.log(this.calendar);
  }

}

In the component template from $ctrl.calendar I get [] , although in the console
[y2016: Object, y2017: Object]
length:0
y2016:Object
y2017:Object
__proto__:Array[0]

And why is length:0 ?((

Answer the question

In order to leave comments, you need to log in

1 answer(s)
_
_ _, 2016-04-19
@Ivan-P

Because it's not PHP (let _period = [];). For associative arrays use Object({}) or Map

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question