[FIXED] Angular: Open file dialog upon button click

Issue

I’m using Angular 8.
Upon button click I want to open a file dialog, select a file and then call an event that will handle this file.

Thank you,
Zvika

I tried the following code in HTML.
But I do not want anything to be displayed in HTML.

HTML

<p-fileUpload name="myfile[]" customUpload="true" auto="true" (uploadHandler)="onOpenFile($event)" accept="application/pdf"></p-fileUpload>

ts

public onOpenFile (event)
{
}

Solution

You can achieve this with normal input tag , you can make it hidden, but at least you need one element to trigger the click event. Check stackblitz

Answered By – Abhinav Kumar

Answer Checked By – Gilberto Lyons (Easybugfix Admin)

Leave a Reply

(*) Required, Your email will not be published