• 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏吧

ERROR在SRC /应用/ logger.ts(18,16):错误TS1005: ‘(’ 预期

angular 来源:user2568391 10次浏览

这是我班记录,并在这里将在setTimeout的显示错误功能 -ERROR在SRC /应用/ logger.ts(18,16):错误TS1005: ‘(’ 预期

export class logger{ 

    WriteLogger() { 

     let dateTime,dd,mm,yyyy,h,m,s,m1,s1; 
     console.log("logger class is called"); 
     //console.log(new Date().getCurrent); 
     dateTime = new Date(); 
     dd = dateTime.getDate(); 
     mm = dateTime.getMonth() + 1; 
     yyyy = dateTime.getFullYear(); 
     h = dateTime.getHours(); 
     m = dateTime.getMinutes(); 
     s = dateTime.getSeconds(); 
     m = this.checkTime(m); 
     s = this.checkTime(s); 

     setTimeout((=> {   
      console.log(dd + "/" + mm + "/" + yyyy + " The Current Time is " + h +":" + m + ":" +s); 
     }),500); 
    } 
    checkTime(i){ 
     if(i<10){ 
      i = "0" + i; 
     } 
    } 
} 

但我正在此错误:

ERROR in src/app/logger.ts(18,16): error TS1005: ‘(‘ expected


===========解决方案如下:

setTimeout应该self invoking

变化setTimeout

setTimeout((=> { 
    console.log(dd + "/" + mm + "/" + yyyy + " The Current Time is " + h +":" + m + ":" +s); 
}),500); 

setTimeout(() => { 
    console.log(dd + "/" + mm + "/" + yyyy + " The Current Time is " + h +":" + m + ":" +s); 
}, 500)() 

版权声明:本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系管理员进行删除。
喜欢 (0)