我正在使用 Angular2 和 Firbase 存储。我正在尝试获取“uploadProgress”值来更新(在 HTML 文件中指定),但是可以更新 uploadTask.on 函数中的“uploadProgress”变量。是因为它在另一个线程上运行吗?这个问题的任何解决方法?希望可以有人帮帮我。谢谢
=======================================================================
import { Component } from '@angular/core';
import { AngularFire, FirebaseListObservable } from 'angularfire2';
import * as firebase from 'firebase';
@Component({
selector: 'app-create-folder',
templateUrl: './create-folder.component.html'
})
export class CreateFolderComponent {
public fItem: FolderItem;
public f: File;
public storageRef: Storage;
public uploadProgress = 0;
constructor(public af: AngularFire) {}
onSubmit() {
const storageRef = firebase.storage().ref().child('myclient/' +
this.fItem.file_name);
var uploadTask = storageRef.put(this.f);
uploadTask.on('state_changed', function(snapshot){
this.uploadProgress = (snapshot.bytesTransferred / snapshot.totalBytes) *
100;
});
}
}