Angular 这个函数有什么问题?当我运行ng serve(角度)时,它经常显示语法错误
每次我运行ng serve时,它都会抛出一个语法错误,或者说:;缺失或)缺失或,缺失。有趣的是,你可以删除一个;例如,单击“保存”,它将在下次键入ng serve时开始完美运行,它显示类似的错误,并且您添加了相同的错误,或者;上一次移除后,它会重新开始工作,直到下一次ng发球。代码如下:Angular 这个函数有什么问题?当我运行ng serve(角度)时,它经常显示语法错误,angular,typescript,angular6,Angular,Typescript,Angular6,每次我运行ng serve时,它都会抛出一个语法错误,或者说:;缺失或)缺失或,缺失。有趣的是,你可以删除一个;例如,单击“保存”,它将在下次键入ng serve时开始完美运行,它显示类似的错误,并且您添加了相同的错误,或者;上一次移除后,它会重新开始工作,直到下一次ng发球。代码如下: OnFileSelected(event) { const file: File = event[0]; this.ReadAsBase64(file) .then(result
OnFileSelected(event) {
const file: File = event[0];
this.ReadAsBase64(file)
.then(result => {
this.selectedFile = result;
})
.catch (err => {this.error = err; setTimeout(() => {this.error = ''; }, 2000; } ); )
}
所有这些错误都与,;)有关或者}
发生在这里:
.catch (err => {this.error = err; setTimeout(() => {this.error = ''; }, 2000; } ); )
}
如何解决这个问题?应该
.catch(err => { this.error = err; setTimeout(() => { this.error = ''; }, 2000) } )
或者最好是
const file: File = event[0];
this.ReadAsBase64(file)
.then((result) => {
this.selectedFile = result;
})
.catch((err) => {
this.error = err;
setTimeout(() => {
this.error = '';
}, 2000);
});
因为分号和括号放错了位置,所以更容易阅读。他们说,你可以通过按[code>Enter(键盘上的一个大按钮)来尝试使用换行符。这样你就能更好地阅读代码了。顺便说一句,这是离题的,因为这都是关于打字错误之类的错误,我也会删除任何空格,使它更难阅读)你们这些家伙是邪恶的…就像他的代码一样