1

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 ?

2
  • I think there is no way to accomplish that, without actually having some kind of implementation that takes care of the file upload. So either you need to completely re-implement the entire API that usually takes care of the file upload, or have a hidden input that you may trigger as described here: stackoverflow.com/questions/37320135/… Commented May 27, 2020 at 6:38
  • What have you tried so far in typescript/javascript? This is a very open question and you haven't provided anything to help us help you Commented May 27, 2020 at 7:48

1 Answer 1

5

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(); 
  }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.