0
我有一個服務以角度2寫入,用於將圖像上傳到firebase。 代碼:Firebase功能無法識別角度4
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導入更改爲「聲明var firebase」來解決此問題,但這種方法無效。
這工作得很好!謝謝。 –