我有一个用角度2写的服务,用于将图像上传到firebase。 代码是:
import {Injectable} from "@angular/core";
import {AngularFireDatabase} from "angularfire2/database";
import {FileUpload} from "../objects/file";
import * as firebase from 'firebase';
@Injectable()
export class UploadFileService {
private basePath = '/uploads';
constructor(private db: AngularFireDatabase) {}
pushFileToStorage(fileUpload: FileUpload, progress: {percentage: number}) {
const storageRef = firebase.storage().ref();
const uploadTask = storageRef.child(`${this.basePath}/${fileUpload.file.name}`).put(fileUpload.file);
uploadTask.on(firebase.storage.TaskEvent.STATE_CHANGED,
(snapshot) => {
// in progress
const snap = snapshot as firebase.storage.UploadTaskSnapshot;
progress.percentage = Math.round((snap.bytesTransferred / snap.totalBytes) * 100);
},
(error) => {
// fail
console.log(error);
},
() => {
// success
fileUpload.url = uploadTask.snapshot.downloadURL
fileUpload.name = fileUpload.file.name
this.saveFileData(fileUpload);
}
);
}
private saveFileData(fileUpload: FileUpload) {
this.db.list(`${this.basePath}/`).push(fileUpload);
}
}
此代码在" firebase.storage"上给出了错误。函数"属性存储在类型firebase static"
上不存在我已经阅读了一篇关于这句话的帖子,可以通过将firebase导入更改为"声明var firebase"来解决这个问题。但这没效果。
答案 0 :(得分:0)
将您的行更改为:
import menu from 'menu';
第一行导入类型。第二个只进口火力储存库。