AngularFire和Firebase - 可以同时使用吗?

时间:2016-09-08 09:54:57

标签: angular firebase ionic2 angularfire2

我使用Ionic2和firebase。我已经看到了两种在app.ts中初始化firebase的方法 这样做的首选方式是什么以及如何使用这两种功能?当我在ionicBootstrap()中初始化时,我失去了firebase函数,当我在构造函数中执行它时,我失去了angularfire函数。

要使用angularfire函数,它将在ionicBootstrap中初始化

ionicBootstrap(MyApp, [
    FIREBASE_PROVIDERS,
    // Initialize Firebase app  
    defaultFirebase({
        apiKey: "XXXXXX-XXXXXXXXXXXXXXXXXX-XXXXXX",
        authDomain: "XXXXXX.firebaseapp.com",
        databaseURL: "https://XXXXXX.firebaseio.com",
        storageBucket: "XXXXXX.appspot.com"
    }),
    provide('AppStore', { useValue: appStore }) ])

要使用firebase函数,它将在构造函数

中初始化
constructor(private platform:Platform) {

    platform.ready().then(() => {
        // Okay, so the platform is ready and our plugins are available.
        // Here you can do any higher level native things you might need.
        StatusBar.styleDefault();

        // Initialize Firebase
        var config = {
            apiKey: "XXXXXX-XXXXXXXXXXXXXXXXXX-XXXXXX",
            authDomain: "XXXXXX.firebaseapp.com",
            databaseURL: "https://XXXXXX.firebaseio.com",
            storageBucket: "XXXXXX.appspot.com"
        };
        firebase.initializeApp(config);

    });
}

我试图在构造函数中为angularfire2移动defaultFirebase(),但它没有成功。我收到此错误:

  

原始例外:Token FirebaseUrl没有提供商! (AngularFire - >   令牌FirebaseUrl)

1 个答案:

答案 0 :(得分:2)

使用此SO问题/答案找到解决方案。

How to get access to native Firebase object when using angularfire2?

我正在使用ionicBootstrap()来初始化firebase并替换

import * as firebase from 'firebase';

通过

declare var firebase : any;