【发布时间】:2019-01-17 15:38:57
【问题描述】:
我有一个父组件,其中有 2 个输入 type="file" 元素,它们在文件更改时调用函数 getFileForParent():
<input type="file" (change)="getFileForParent()" />
在我的子组件中,我有一个:
<input type="file" (change)="getFileForChild()" />
但是每当我在子组件上选择一个文件时,父母getFileForParent 就会被调用。
我正在使用ng2-file-upload。
父 ts:
getFileForParent(){
if(this.uploaderForParent.queue[0].file.type != 'application/PDF'){
this.showError("Please select pdf files only");
return;
}
this.uploaderForParent.uploadAll();
}
儿童 ts:
getFileForChild(){
if(this.uploaderForChild.queue[0].file.type != 'application/PDF'){
this.showError("Please select pdf files only");
return;
}
this.uploaderForChild.uploadAll();
}
【问题讨论】:
-
可以分享一下你的ts代码吗
-
@Chellappan 完成。
标签: javascript html angular file-upload ng2-file-upload