如何设置值的数组以动态接受角度4中输入标签的属性

时间:2018-12-21 09:44:08

标签: javascript angular typescript

我有以下输入标签,我需要使用数组动态设置接受值:

 <input #myFile type="file" />

要动态设置接受属性,我正在使用子视图:

@ViewChild("myFile") myFileRef: ElementRef;

ngAfterViewInit() {
    this.myFileRef.nativeElement.accept = ['.pdf','.doc','.docx','.xlsx', '.xls'];
  }

这不起作用,可以使用angular或javascript吗?

1 个答案:

答案 0 :(得分:1)

它的工作原理只是将数组中的内容更改为字符串:

ngAfterViewInit() {
    this.myFileRef.nativeElement.accept = [".doc",".docx",".xlsx", ".xls"];
  }

在这里,您在尝试选择某些文件时找不到PDF的文件类型。

Working demo.