我想要为我的文件上传创建一个进度条。
我使用的上传是:https://www.npmjs.com/package/ng2-file-upload.
app.component.html
<div class="container-fluid">
<div class="row">
<div class="col-md-12">
<input type="file" name="myFile" ng2FileSelect [uploader]="uploader" />
</div>
</div>
<div class="row">
<div class="col-md-12">
<button type="button" class="btn btn-success btn-s" (click)="uploader.uploadAll()" [disabled]="!uploader.getNotUploadedItems().length">
Upload an Image
</button>
</div>
</div>
</div>app.component.ts
import { Component, ViewChild } from '@angular/core';
import { FileUploader, FileSelectDirective } from 'ng2-file-upload';
const URL = 'url to API';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
public uploader: FileUploader = new FileUploader({ url: URL, itemAlias: 'myFile' });
ngOnInit() {
this.uploader.onAfterAddingFile = (file) => { file.withCredentials = false; };
this.uploader.onCompleteItem = (item: any, response: any, status: any, headers: any) => {
console.log('ImageUpload:uploaded:', item, status, response);
alert('File uploaded successfully');
};
}
}一切都很好,但我想放一个进度条,只有这个。
发布于 2018-08-10 05:44:10
你可以听听这里的进展
this.uploader.onProgressItem = (progress: any) => {
console.log(progress['progress']);
};发布于 2019-06-25 21:16:33
在您的app.component.html中包括:
<div class="progress" style="margin-bottom: 0;">
<div class="progress-bar" role="progressbar" [ngStyle]="{ 'width': uploader.progress + '%' }"></div>
</div>
https://stackoverflow.com/questions/51779303
复制相似问题