Firebase存储不适用于离子3& AngularFire 4.0.0 rc。 返回此错误消息。 firebase.storage()不带参数或Firebase应用程序实例
//错误 TypeError:this.fb.storage不是函数
//Module
import {NgModule} from '@angular/core';
import {IonicPageModule} from 'ionic-angular';
import {ProfilePage} from './profile';
import 'firebase/storage'
@NgModule({
declarations: [
ProfilePage,
],
imports: [
IonicPageModule.forChild(ProfilePage),
],
exports: [
ProfilePage
]
})
export class ProfilePageModule {
}
//components
import {Component, Inject} from '@angular/core';
import {NavController, IonicPage} from 'ionic-angular';
import {NgForm} from "@angular/forms";
import {AngularFireAuth} from 'angularfire2/auth';
import {AngularFireDatabase, FirebaseListObservable, FirebaseObjectObservable} from 'angularfire2/database';
import * as firebase from 'firebase'; // for typings
import { FirebaseApp } from 'angularfire2';
@ionicpage()
@component({
selector: 'page-profile',
templateUrl: 'profile.html',
})
export class ProfilePage {
file:any;
forUpLoadRef: FirebaseListObservable;
userRef: FirebaseObjectObservable;
storageRef:any;
constructor(public navCtrl: NavController, public af: AngularFireAuth,
public db: AngularFireDatabase, private fb: FirebaseApp) {}
UploadNewImage(){
this.file = (document.getElementById('inputFileId')).files[0];
console.log("file recived"+ JSON.stringify(this.file.name));
let storageRef = this.fb.storage().ref();
var metadata = {
contentType: 'image/*'
};
this.storageRef.child('images/'+this.file.name).put(this.file,metadata)
}
}
//error
TypeError: this.fb.storage is not a function
答案 0 :(得分:3)
只需在父模块中添加import 'firebase/storage';
即可
https://github.com/angular/angularfire2/issues/1015