Angular : How to Add/Remove Files in the Angular?

前端 未结 5 1516
旧巷少年郎
旧巷少年郎 2021-01-18 10:11

Here i choose multiple images and shows using *ngFor And there I have placed a delete button which is appear in the screenshot, click on delete button i want to

5条回答
  •  -上瘾入骨i
    2021-01-18 10:39

    event.target.files is already an array, which is why you can iterate over it with ngFor. When you assign selectedFile = event.target.files, you are making it an array. Try this:

    selectedFile: File;
    ArrayOfSelectedFile = new Array();
    
    onFileChanged(event : any) {
      this.selectedFile = event.target.files[0];
      this.ArrayOfSelectedFile = event.target.files;
    }
    
    removeSelectedFile(index){
      this.ArrayOfSelectedFile.splice(index,1);
    }
    
    

    {{selected.name}}

提交回复
热议问题