打字稿中的错误:属性.ref类型' AngularFireStorageModule'

时间:2018-05-09 13:16:36

标签: typescript firebase ionic3 firebase-storage angularfire2

我试图在Ionic中使用AngularFire将图像上传到firebase,但我一直收到错误'Property '.ref' does not exist on type 'AngularFireStorageModule'.'

导入:

import { AngularFireAuth } from 'angularfire2/auth';
import { AngularFirestore, AngularFirestoreCollection } from 'angularfire2/firestore';
import { AngularFireStorageModule } from 'angularfire2/storage';

import * as firebase from 'firebase/app';
import { enableLogging } from '@firebase/database-types';

.ref错误

 for(var i = 0; i < this.imagePaths.length; i++){
    console.log("Adding photo's" + this.imagePaths[i]);
        const filePath = 'images/' + this.docRef + '/';
        const ref = this.storage.ref(filePath);
        const task = ref.put(this.imagePaths[i]).then((snapshot) => {
          console.log('Uploaded an image!');
        });
  } 

错误发生在const ref = this.storage.ref(filePath);

有谁知道为什么这不起作用?我在网上搜索,但所有的教程都像我一样做了一切。

1 个答案:

答案 0 :(得分:0)

import { AngularFireStorage } from 'angularfire2/storage';
constructor(private storage: AngularFireStorage)

uploadFile(file){
  const filePath = 'images/' + this.docRef + '/';
  const task = this.storage.upload(filePath, file);

  task.percentageChanges().subscribe(per => {
    console.log(per);
  });

  task.downloadURL().subscribe(url => {
    console.log(url);
  }
}

来源AngularFire2 Docs