我想从函数中发送文件的名称,我可以发出输出并发送到另一个组件。我试过一个原型但我无法解决它。
file(file: File): void {
UploadFS.selectFiles(function(file){
var today = new Date();
var dd = today.getTime();
let photo = {
name: file.name + dd,
size: file.size,
type: file.type
};
let worker = new UploadFS.Uploader({
store: ImagesStore,
data: file,
file: photo,
onComplete(file) {
console.log(file.name + ' has been uploaded');
this.check = file.name;
}
});
worker.start();
this.check = photo.name;
console.log(photo.name); //here the name of file is visible
});
console.log("check outside33 ",this.check); // here not: output: undefinded
//this.onFile.emit(this.check);
}
答案 0 :(得分:1)
更改
UploadFS.selectFiles(function(file){
到
UploadFS.selectFiles((file)=>{
您的this
未提及您的组件
或使用旧的js方式:
var self = this; //<-- assign this to self here
UploadFS.selectFiles(function(file){
var today = new Date();
var dd = today.getTime();
let photo = {
name: file.name + dd,
size: file.size,
type: file.type
};
let worker = new UploadFS.Uploader({
store: ImagesStore,
data: file,
file: photo,
onComplete(file) {
console.log(file.name + ' has been uploaded');
self.check = file.name;
}
});
worker.start();
self.check = photo.name; //<-- use self here
console.log(photo.name); //here the name of file is visible
});