[英]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.