1
votes

I am new to Angular 6. With the following code:

export class DateComponent implements OnInit {

  currentDate: string = new Date().toDateString;

  constructor() { }

  ngOnInit() {
  }
}

I am getting the following error, but I do not know what may be causing it.

error TS2322: Type '() => string' is not assignable to type 'string'.

1

1 Answers

3
votes

You should invoke the function, not assign the function object. Adding () at the end should fix it

currentDate: string = new Date().toDateString();