簡體   English   中英

如何在 Angular 中不點擊按鈕觸發 OnChangeFile 輸入?

[英]how can i trigger OnChangeFile input without Button Click in Angular?

我正在嘗試將文件上傳到 AWS,但我不想按“選擇文件”按鈕。 它應該自動觸發有沒有辦法實現這個

在我的.html 文件中

<div class="content">
  <input (change)="onChangeFile($event)" type="file" />
</div>

在 my.ts 文件中

 async onChangeFile(event: any) {
    console.log(event.target.files[0]);
    this.fileSelected = event.target.files[0];
    console.log(environment);
    console.log('Uploaded');
    await this.S3CustomClient.uploadFile(
     .uploadFile(this.fileSelected, this.fileSelected.type, undefined, this.fileSelected.name, "private")
      .then((data: UploadResponse) => console.log(data))
      .catch((err: any) => console.error(err))

出於安全原因,文件選擇器對話框只能在用戶激活時顯示 - 例如單擊事件。 你想要的是不可能的。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM