I have a problem:
I have an array named _daysConfig<DayConfig>
If I fill it like this, it works:
_daysConfig: DayConfig[] = [
{
date: new Date('Wed Jul 22 2020 21:06:00 GMT+0200 (heure d’été d’Europe centrale)'),
subTitle: 'x',
marked: true
},
{
date: new Date('Wed Jul 31 2020 21:06:00 GMT+0200 (heure d’été d’Europe centrale)'),
subTitle: 'y',
marked: true
}, ];
But if I fill it from another array(allEvents) with .push(), it does not work anymore:
this.allEvents.forEach(element => {
this._daysConfig.push(
{
date: new Date(element.startTime),
subTitle: 'x',
marked: true
},
);
});
When I look in the chrome console, it looks like this:

Someone could help me, please?
EDIT :
I tried this
Try pushing the "DayConfig" object instead of normal object.
this.allEvents.forEach(element => {
this._daysConfig.push(
new DayConfig({
date: new Date(element.startTime),
subTitle: 'x',
marked: true
})
);
});
Or something like this
this.allEvents.forEach(element => {
const obj = new DayConfig();
obj.date = new Date(element.startTime);
obj.subTitle = 'x';
obj.marked = true;
this._daysConfig.push(obj);
});
But it didn't work.
DayConfig is not an object but a type.
Here is my code :
import { Component, ViewChild } from '@angular/core';
import { CalendarComponentOptions, CalendarComponent, DayConfig } from '../../assets/ion2-calendar';
import * as moment from 'moment';
import { AngularFireDatabase } from '@angular/fire/database';
@Component({
selector: 'app-home',
templateUrl: 'home.page.html',
styleUrls: ['home.page.scss'],
})
export class HomePage {
@ViewChild('calendar', { read: CalendarComponent }) calendarRef: CalendarComponent;
dateRange: { from: string; to: string; };
date: string;
type: 'string';
typeEvent: string = 'task';
dateDay: number;
viewDate: Date;
user: string = 'Clémentine';
showAddEvent: boolean;
i = 0;
newEvent = {
user: '',
title: '',
description: '',
startTime: '',
startHour: '',
place: '',
repeat: '',
altern: false
};
allEvents = [];
_daysConfig: DayConfig[] = [];
_daysConfig2: DayConfig[] = [
{
date: new Date('Wed Jul 22 2020 21:06:00 GMT+0200 (heure d’été d’Europe centrale)'),
subTitle: 'x',
marked: true
},
{
date: new Date('Wed Jul 31 2020 21:06:00 GMT+0200 (heure d’été d’Europe centrale)'),
subTitle: 'y',
marked: true
},
];
optionsRange: CalendarComponentOptions = {
monthFormat: 'MMMM YYYY',
monthPickerFormat: ['Janv', 'Févr', 'Mars', 'Avril', 'Mai', 'Juin', 'Juillet', 'Août', 'Sept', 'Oct', 'Nov', 'Déc'],
pickMode: 'single',
color: 'primary',
weekdays: ['D', 'L', 'M', 'M', 'J', 'V', 'S'],
weekStart: 0,
from: new Date(),
showAdjacentMonthDay: false,
showToggleButtons: true,
daysConfig: this._daysConfig
};
constructor(public calendarComponent: CalendarComponent, public afDB: AngularFireDatabase) {
moment.locale('fr-ch');
this.loadEvents();
console.log('DaysConfig :');
console.log(this._daysConfig);
console.log('daysConfig2 :');
console.log(this._daysConfig2);
}
userChange($event) {
if ($event.detail.value === 'Clémentine') {
this.user = 'Clémentine';
} else {
this.user = 'Bertrand';
}
}
convertDate(date) {
this.date = moment().format('YYYY-MM-DD');
return date;
}
showHideForm() {
this.showAddEvent = !this.showAddEvent;
if (this.typeEvent === 'rdv') {
this.typeEvent = 'task';
}
}
addEvent() {
this.afDB.list('Events').push({
user: this.user,
typeEvent: this.typeEvent,
title: this.newEvent.title,
startTime: this.newEvent.startTime,
description: this.newEvent.description,
startHour: this.newEvent.startHour,
place: this.newEvent.place,
repeat: this.newEvent.repeat,
altern: this.newEvent.altern
});
this.showHideForm();
}
loadEvents() {
this.afDB.list('Events').snapshotChanges(['child_added']).subscribe(actions => {
actions.forEach(action => {
this.allEvents.push({
user: action.payload.exportVal().user,
typeEvent: action.payload.exportVal().typeEvent,
title: action.payload.exportVal().title,
startTime: new Date(action.payload.exportVal().startTime),
description: action.payload.exportVal().description,
startHour: new Date(action.payload.exportVal().startHour),
place: action.payload.exportVal().place,
repeat: action.payload.exportVal().repeat,
altern: action.payload.exportVal().altern
});
});
this.daysConfig();
console.log('AllEvents :');
console.log(this.allEvents);
});
this.i = 0;
}
daysConfig() {
this.allEvents.forEach(element => {
this._daysConfig.push(
{
date: new Date(element.startTime),
subTitle: 'x',
marked: true
},
);
});
this.i++;
}
getCalendarViewDate() {
let viewDate = this.calendarRef.getViewDate()._d;
viewDate = viewDate.toString().substring(0, 8) + this.dateDay + viewDate.toString().substring(10, 100);
return viewDate;
}
setCalendarViewDate() {
this.calendarRef.setViewDate('2018-02-01');
}
onChange($event) {
this.dateDay = $event.title;
this.newEvent.startTime = this.getCalendarViewDate();
}
typeEventChange($event) {
if ($event.detail.value === 'task') {
this.typeEvent = 'task';
} else {
this.typeEvent = 'rdv';
}
}
}
And here is my chrome console : Chrome Console
allEventslook like?thiskeyword but we don't know where is that coming from.