【问题标题】:How add null inputs while files are uploading, and then this files set to input如何在文件上传时添加空输入,然后将此文件设置为输入
【发布时间】:2018-01-04 09:50:25
【问题描述】:

例如我应该上传3个文件。当我点击“上传”时应该出现 3 个输入。当文件完成上传时,它们将写入此输入。 我循环添加文件。当文件上传时,用户应该看到预加载器

onSubmit(e: any) {
this.alertService.clearMessage();

for (let i = 0; i < this.files.length; i++) {
  this.fileUploadService.upload(this.files).subscribe(data => {
    if (!data) {
      this.alertService.error("Select files");
    }
    else {
      this.newRow.push(" ");
      this.filesList.push(data);
      this.alertService.success("File url is: " + data.url);
    }
  }, error => {
    this.alertService.error(error._body);
  });
}

还有我的html

<tr *ngFor="let file of filesList; let i=index" >
      <td><input class="form-control input-sm" *ngIf="file.url" value="{{ file.url}}" /></td>
      <td>{{ file.size/1024 | round }} Kb</td>
      <td>{{ file.modified * 1000 | date:'MM-dd-yyyy' }} </td> 
      <td>
        <img *ngIf="deleting == i" src="data:image/gif;"/>
        <a *ngIf="deleting !== i"  class="glyphicon glyphicon-trash" (click)="onRemove(i)"></a>
      </td>
    </tr>

【问题讨论】:

    标签: javascript angular typescript angular2-forms


    【解决方案1】:

    解决了。

    onSubmit(e: any) {
    this.alertService.clearMessage();
    
    for (let i = 0; i < this.files.length; i++) {
    // Im getting empty fields by this way and know the number of uploaded files
      let newItemId = this.filesList.push(this.fake) - 1; 
    
      this.fileUploadService.upload(this.files).subscribe(data => {
        if (!data) {
          this.alertService.error("Select files");
        }
        else {
          //  push data in array of getting lenght
          this.filesList[newItemId] = data;
          this.alertService.success("File url is: " + data.url);
        }
      }, error => {
        this.alertService.error(error._body);
      });
    }
    

    }

    【讨论】:

      猜你喜欢
      • 2014-01-22
      • 2020-04-15
      • 1970-01-01
      • 1970-01-01
      • 2012-03-23
      • 2023-04-02
      • 1970-01-01
      • 2010-11-23
      • 2015-08-06
      相关资源
      最近更新 更多