2017-11-11 77 views
0

我有一个kendo-upload组件只上传一个文件。文件上传后,我需要清除列表或上传的文件。如何重置上传的文件列表在Kendo Angular上传组件

  1. 一个文件被选择

    enter image description here

  2. Initial state - before a file is selected

  3. 后一文件被上传之后初始状态

    enter image description here

我需要的第3步中看起来像第1步=一样,如果我会点击Clear按钮。

我试图绑定到(success)事件做:

一个。 this.pictureUpload.fileList.clear();

b。 this.pictureUpload.fileList.remove(this.pictureFilePreview.uid);

但总是从uploadService得到一个例外:

enter image description here

我没有深入到uploadService源代码,并明白为什么我得到一个异常。我也看了一下upload-component的源代码,并试图了解如何在外部执行Clear按钮的方法,但没有找到任何简单的方法。我认为我过分复杂化,必须有一些我没有发现的简单解决方案。

回答

0

你可以使用模型绑定来做到这一点。

import { FileInfo } from '@progress/kendo-angular-upload'; 

首先捕捉完成的事件在剑道上载:

[(ngModel)]="myFiles" (complete)="uploadCompleted()" 

添加一个成员:

 myFiles: Array<FileInfo> = []; 

,并捕获事件并重置文件列表为空:

public uploadCompleted(){ 
    this.myFiles = []; 
}