2017-07-28 14 views
0

と入力します。私は3つのファイルをアップロードする必要があります。私が "アップロード"をクリックすると、3つの入力が表示されるはずです。ファイルのアップロードが完了すると、この入力に書き込まれます。 ファイルをループで追加します。ファイルがアップロードされている間、ユーザーが見るべきプリローダーファイルのアップロード中にnull入力を追加する方法は、

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

}

関連する問題