Type 'string' is not assignable to type 'Moment' error

Type 'string' is not assignable to type 'Moment' error

I have an object like this:

I have an object like this:

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 place I need to get the date from the form I'm using, but in the second case that is giving me the problem, I just need to get the date from the system and use it in the new created object (without the error, that I do not understand since the date is also a 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; }

So, in both cases (1) and (2) I can not make it work and I do not understand why.

angular typescript

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Basics of Angular: Part-1

What is Angular? What it does? How we implement it in a project? So, here are some basics of angular to let you learn more about angular. Angular is a Typesc

TypeScript, Angular, Firebase & Angular Material Master class Tutorial

As the course progresses, you'll get familiar with: TypeScript, Angular Application Architecture, and Angular CLI. Angular Modules and Angular Components. Angular's Component LifeCycle Hooks....

Angular Tutorial: Create a CRUD App with Angular CLI and TypeScript

Angular Tutorial: Create a CRUD App with Angular CLI and TypeScript. This tutorial gets you off the ground with Angular. We are going to use the official CLI (command line) tool to generate boilerplate code.

Angular: Novidades Angular v9 Ivy: TypeScript 3.7

Mais um vídeo da série sobre Angular v9 e Angular Ivy! Esse tutorial é uma dica rápida mostrando as duas maiores novidades to TypeScript 3.7 que é o operador de optional chaining e o operador de coalescência nula.

Data Table Pagination Using Angular Material

Explaining how to perform pagination of the data on the HTTP observable stream with the help of Angular Material