Selecting a file when we click on an input element of type file is straight forward and there is nothing complicated. But many times you may want to create a difference UI in which a user may have to click on a button to trigger file selection. For example, take a look at the image below

If you want to implement such type of UI, then you may have to trigger select file window when you click on the change button. We can do it easily in Angular 13 applications.

To implement file selection on the click of a button, create an input element and make it not visible. Then create a button clicking on which you want to trigger file selection. When the user clicks on that button, also trigger a click event on the input element which is not visible.

Component HTML:

<input type="file" style="display: none;" #fileInput>

<svg xmlns="" width="64" height="64" fill="currentColor" class="bi bi-person-circle"
    viewBox="0 0 16 16">
    <path d="M11 6a3 3 0 1 1-6 0 3 3 0 0 1 6 0z" />
    <path fill-rule="evenodd"
        d="M0 8a8 8 0 1 1 16 0A8 8 0 0 1 0 8zm8-7a7 7 0 0 0-5.468 11.37C3.242 11.226 4.805 10 8 10s4.757 1.225 5.468 2.37A7 7 0 0 0 8 1z" />
<button class="btn btn-outline-dark btn-lg ms-3" (click)=" ">Change</button>

In the previous code, we have an input element of type file and we set its display value to none. We created a template reference variable fileInput on that element. When the user clicks on the button, we did event binding on it and running the click method of the input element.

Keeping the code that we are executing when an event happens in the template may sometimes causes confusion. So, you can create a method in the ts file and pass template reference variable to it when the user clicks on the button.

Then the code for the button can be

<button class="btn btn-outline-dark btn-lg ms-3" (click)=" triggerSelectFile(fileInput) ">Change</button>


triggerSelectFile(fileInput: HTMLInputElement) {

If you want to do it in Pure JavaScript way, then check this post Select file on Button Click in JavaScript