2

I'm using ng2FileUpload to create the drag-n-drop for upload, but I also want to allow users to click on the drop area to open the file dialog.

Considering I have this input:

<input type="file" ng2FileSelect [uploader]="uploader" style="display: none" />

How can I show the file dialog from the Angular 4 typescript code?

1 Answer 1

6

I've been able to do it this way:

Template:

<input type="file" ng2FileSelect [uploader]="uploader" hidden #fileInput />

Angular Component:

@ViewChild('fileInput') fileInput:ElementRef;

public openFileDialog():void {
    let event = new MouseEvent('click', {bubbles: false});
    this.fileInput.nativeElement.dispatchEvent(event);
  }
Sign up to request clarification or add additional context in comments.

1 Comment

A simple this.fileInput.nativeElement.click() also works

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.