I've encountered an issue:
I'm working with an array called _daysConfig<DayConfig>
When I manually populate it like this, everything functions correctly:
_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
}, ];
However, when I attempt to fill it using another array(allEvents) and the .push()
method, it stops working:
this.allEvents.forEach(element => {
this._daysConfig.push(
{
date: new Date(element.startTime),
subTitle: 'x',
marked: true
},
);
});
Upon inspection in the Chrome console, the output appears like this:
https://i.sstatic.net/dtVm4.png
If anyone could provide assistance, I'd greatly appreciate it.
EDIT :
I attempted this approach
Try pushing the "DayConfig" object instead of a standard object.
this.allEvents.forEach(element => {
this._daysConfig.push(
new DayConfig({
date: new Date(element.startTime),
subTitle: 'x',
marked: true
})
);
});
Or consider 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);
});
Unfortunately, these methods didn't yield the desired results.
Note that DayConfig is not an object, but rather a type.
Here's a snippet of 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
};
...
...
Additionally, you can refer to my chrome console for more insights : Chrome Console