Angular 6中ng2-file-upload中的进度栏 [英] Progress Bar in ng2-file-upload in Angular 6
本文介绍了Angular 6中ng2-file-upload中的进度栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想为我的文件上传创建进度条.
Id like to create a progress bar to my file upload.
我正在使用的上载是: https://www.npmjs.com/package/ng2-file-upload.
The Upload I'm using is: 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');
};
}
}
一切正常,但我只想放一个进度条.
Everything is working fine but Id like to put a progress bar, only this.
推荐答案
您可以在此处听进度
this.uploader.onProgressItem = (progress: any) => {
console.log(progress['progress']);
};
这篇关于Angular 6中ng2-file-upload中的进度栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文