Reputation: 209
i want to oen upload dialog by typescript in angular 9 .
i not want to using this way : create input and dispaly:none
<input type="file" ng2FileSelect [uploader]="uploader" style="display: none" />
i want to open file upload dialog with code .
how open the upload file dialog without the create input file and just using the typescript or javascript Code ?
Upvotes: 1
Views: 1841
Reputation: 17610
If there is no file input then you can't open file browser. This file input is readonly input just one way and work while clicked due to security issues. Then You need file input to open dialog.
One way is to use Viewchild and trigger click it.
in html write Viewchild name
<input type="file" style="display: none;" #file />
in component can call it in ngAfterViewInit
@ViewChild("file") file : ElementRef;
ngAfterViewInit(){
console.log(this.file.nativeElement);
this.file.nativeElement.click();
}
Upvotes: 5