I have calendar component with data property decorated as @Input():
import { Component, OnInit, Input, OnChanges, SimpleChanges } from '@angular/core';
@Component({
selector: 'app-calendar',
templateUrl: './calendar.component.html',
styleUrls: ['./calendar.component.css']
})
export class CalendarComponent implements OnInit, OnChanges {
@Input() data: CalendarDay[];
constructor() {
this.data = [];
}
ngOnInit() {
this.initDays();
}
ngOnChanges(changes: SimpleChanges) {
console.log(this.data);
console.log(changes.data);
}
}
I pass data in from another component like that:
<app-calendar [data]="this.calendarData"></app-calendar>
And passed data gets rendered by *ngFor in the calendar component (it renders perfectly and everything works just fine):
<div *ngFor="let item of data">{{item.date}}</div>
I want to parse this data first before rendering it into view and whenever i try to console.log data property within the calendar component i get strange array, its shows as empty, i can 'open' it from browser console:
.
And when i try to log value like that:
console.log(this.data[0])
or
console.log(changes.data.currentValue[0])
i get undefined value.