Javascript 在同一组件内调用函数表示此。checkUpdate不是函数
我有以下上传功能,可以将文件上传到s3Javascript 在同一组件内调用函数表示此。checkUpdate不是函数,javascript,angular,typescript,Javascript,Angular,Typescript,我有以下上传功能,可以将文件上传到s3 _.each(files, file => { let uuid = this.appMsgService.getGUID(); let bucket = new AWS.S3({ params: { Bucket: 'myBucket' } }); let params = { Key: `\source/${uuid}.pdf`, Body: file }; this.fileNames[fi
_.each(files, file => {
let uuid = this.appMsgService.getGUID();
let bucket = new AWS.S3({ params: { Bucket: 'myBucket' } });
let params = { Key: `\source/${uuid}.pdf`, Body: file };
this.fileNames[file.name] = `${uuid}.pdf`;
this.fileName = `${uuid}`;
bucket.upload(params, function (error: any, res: any) {
uploadCount += 1;
console.log('error', error);
console.log('response', res);
if (uploadCount === files.length) {
this.interval = setInterval(() => {
console.log(JSON.stringify(this.fileNames));
this.checkUpdate(this.fileNames);
}, 3000);
}
});
});
我在同一个组件中有另一个函数,它使用计时器调用并检查更新
checkUpdate(filenames: any) {
}
我已经在上传的回调中添加了方法调用,但它给出了一个错误,即this.checkUpdate不是一个函数
bucket.upload(参数,函数(错误:any,res:any){
到
您的此
不是指您的组件
老办法:
var self = this; //<-- use self to refer to the component in the lexical scope
bucket.upload(params, function (error: any, res: any) {
uploadCount += 1;
console.log('error', error);
console.log('response', res);
if (uploadCount === files.length) {
self.interval = setInterval(() => {
console.log(JSON.stringify(self.fileNames));
self.checkUpdate(self.fileNames);
}, 3000);
}
});
var self=this;//{
log(JSON.stringify(self.fileNames));
self.checkUpdate(self.filename);
}, 3000);
}
});
更改
bucket.upload(参数,函数(错误:any,res:any){
到
您的此
不是指您的组件
老办法:
var self = this; //<-- use self to refer to the component in the lexical scope
bucket.upload(params, function (error: any, res: any) {
uploadCount += 1;
console.log('error', error);
console.log('response', res);
if (uploadCount === files.length) {
self.interval = setInterval(() => {
console.log(JSON.stringify(self.fileNames));
self.checkUpdate(self.fileNames);
}, 3000);
}
});
var self=this;//{
log(JSON.stringify(self.fileNames));
self.checkUpdate(self.filename);
}, 3000);
}
});
停止此行上的调试器。选中Update
行。检查此
的值。然后仔细想想。停止这一行上的调试器。选中update
行。检查此
的值。然后好好想想。