Angular 5 : 'new'关键字只能调用void函数
Angular 5 : Only a void function can be called with the 'new' keyword
我正在尝试获取 Date.now();当按下回车键但我得到一个错误。 : (
网络上似乎也没有很多关于此错误的信息。
export class DashboardComponent implements OnInit {
onEnter(event){
if(event.key === "Enter"){
this.calculateTime();
}
}
calculateTime(){
if(this.date === undefined){
this.date = new Date.now();
}
}
}
错误是:
error TS2350: Only a void function can be called with the 'new'
keyword.
知道为什么我会收到此错误吗?我该如何解决?
干杯。
Date.now()
函数是静态方法,所以不需要用new
关键字实例化。我认为您在尝试通过调用 new Date()
和此函数混淆来获取当前日期对象时感到困惑。
希望这对您有所帮助!
我正在尝试获取 Date.now();当按下回车键但我得到一个错误。 : (
网络上似乎也没有很多关于此错误的信息。
export class DashboardComponent implements OnInit {
onEnter(event){
if(event.key === "Enter"){
this.calculateTime();
}
}
calculateTime(){
if(this.date === undefined){
this.date = new Date.now();
}
}
}
错误是:
error TS2350: Only a void function can be called with the 'new' keyword.
知道为什么我会收到此错误吗?我该如何解决?
干杯。
Date.now()
函数是静态方法,所以不需要用new
关键字实例化。我认为您在尝试通过调用 new Date()
和此函数混淆来获取当前日期对象时感到困惑。
希望这对您有所帮助!