0

I have following input tag, I need to set the accept value dynamically using array:

 <input #myFile type="file" />

To set the accept properties dynamically i am using view child:

@ViewChild("myFile") myFileRef: ElementRef;

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

This is not working, is it possible using angular or javascript?

2
  • accept expects a string, not an array of syntax errors Commented Dec 21, 2018 at 9:48
  • 2
    Why not using binding like [accept]="value" if you want to change it? Commented Dec 21, 2018 at 9:50

1 Answer 1

1

It works just change what's in your array to strings:

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

Here you wont find PDFs file type while trying to select some files.

Working demo.

Sign up to request clarification or add additional context in comments.

1 Comment

@bambam stackblitz.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.