我有以下输入标签,我需要使用数组动态设置接受值:
<input #myFile type="file" />
要动态设置接受属性,我正在使用子视图:
@ViewChild("myFile") myFileRef: ElementRef;
ngAfterViewInit() {
this.myFileRef.nativeElement.accept = ['.pdf','.doc','.docx','.xlsx', '.xls'];
}
这不起作用,可以使用angular或javascript吗?
答案 0 :(得分:1)
它的工作原理只是将数组中的内容更改为字符串:
ngAfterViewInit() {
this.myFileRef.nativeElement.accept = [".doc",".docx",".xlsx", ".xls"];
}
在这里,您在尝试选择某些文件时找不到PDF
的文件类型。