[英]error TS2322: Type '() => string' is not assignable to type 'string'
我是Angular 6的新手,使用以下代碼:
export class DateComponent implements OnInit {
currentDate: string = new Date().toDateString;
constructor() { }
ngOnInit() {
}
}
我收到以下錯誤,但是我不知道是什么原因引起的。
錯誤TS2322:類型“()=>字符串”不能分配給類型“字符串”。
您應該調用函數,而不要分配函數對象。 在末尾添加()
應該可以解決
currentDate: string = new Date().toDateString();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.