How can I help you?
Trigger click event of input file in Angular Uploader component
26 Feb 20262 minutes to read
You can trigger the click event of the file input element from an external button using the button’s click event. In the following example, the file input’s click event is triggered when an external button is clicked, allowing users to open the file browser without using the default Uploader button.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { UploaderModule } from '@syncfusion/ej2-angular-inputs'
import { Component, AfterViewInit } from '@angular/core';
@Component({
imports: [
UploaderModule
],
standalone: true,
selector: 'app-root',
templateUrl: './default.html',
styleUrls: ['./index.css']
})
export class AppComponent {
public autoUpload: boolean = false;
public path: Object = {
saveUrl: 'https://services.syncfusion.com/angular/production/api/FileUploader/Save',
removeUrl: 'https://services.syncfusion.com/angular/production/api/FileUploader/Remove'
};
ngAfterViewInit(): void {
(document.getElementById('browse') as HTMLElement).onclick = (args) => {
(document.getElementsByClassName('e-file-select-wrap')[0].querySelector('button') as HTMLButtonElement).click();
};
}
}import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));You can also explore Angular File Upload feature tour page for its groundbreaking features. You can also explore our Angular File Upload example to understand how to browse the files which you want to upload to the server.