Essentially, I want to trigger the input button in the page using TypeScript
//its no different than doing it in vanilla JS
let elem = document.getElementById('submitBtn');
let evt = new MouseEvent('click', {
bubbles: true,
cancelable: true,
view: window
});
elem.dispatchEvent(evt);
Use @ViewChild as follows in .ts
@ViewChild('fileInput') fileInput: ElementRef;
let inputElement: HTMLElement = this.fileInput.nativeElement as HTMLElement;
inputElement.click();
In your .html,
<input #fileInput type="file" ng2FileSelect (onFileSelected)="fileUpload($event)"/>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With