2017-07-28 79 views
0

我應該上傳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> 

回答

0

解決它。

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); 
    }); 
} 

}