I am presented with an object structured as follows:
import { Moment } from 'moment';
export interface INewsletter {
id?: number;
creationDate?: Moment;
email?: string;
}
export class Newsletter implements INewsletter {
constructor(public id?: number, public creationDate?: Moment, public email?: string) {}
}
In one particular scenario, I need to fetch the date from a form, whereas in another situation where issues arise, I need to retrieve the system's date and use it in the new object being created (even though both dates are of type moment).
import { Component, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { HttpResponse, HttpErrorResponse } from '@angular/common/http';
import { Observable } from 'rxjs';
import * as moment from 'moment';
import { DATE_TIME_FORMAT } from 'app/shared/constants/input.constants';
import { INewsletter } from 'app/shared/model/newsletter.model';
import { NewsletterService } from '../../entities/newsletter/newsletter.service';
@Component({
selector: 'jhi-footer',
templateUrl: './footer.component.html'
})
export class FooterComponent implements OnInit {
newsletter: INewsletter;
isSaving: boolean;
creationDate: string;
constructor(private newsletterService: NewsletterService, private activatedRoute: ActivatedRoute) {}
ngOnInit() {
this.isSaving = false;
this.creationDate = moment().format(DATE_TIME_FORMAT);
this.newsletter = new Object();
(1) this.newsletter.creationDate = moment().format(this.creationDate);
(2) this.newsletter.creationDate = this.creationDate;
}
Despite my efforts, I cannot seem to resolve the issue in cases (1) and (2), and the reason behind this eludes me.