2017-05-02 3 views
0

私はエラーfirebase.authは()AngularFire

キャッチされない(約束で)を取得するためのいかなるプロバイダをonAuthStateChangedません!私はfirebase.auth().onAuthStateChangedを呼び出そうとしました

。 これがなぜ発生するのかわかりません。助けてください。

import { Component } from '@angular/core'; 
import { Platform } from 'ionic-angular'; 
import { StatusBar } from '@ionic-native/status-bar'; 
import { SplashScreen } from '@ionic-native/splash-screen'; 

import { HomePage } from '../pages/home/home'; 
import { Login } from '../pages/login/login'; 

import firebase from 'firebase'; 

@Component({ 
    templateUrl: 'app.html' 
}) 
export class MyApp { 
    rootPage:any = Login; 
    isAuthenticated = false; 

    constructor(platform: Platform, statusBar: StatusBar, splashScreen: SplashScreen) { 
    firebase.initializeApp({ 
     apiKey: "AIzaSyC94rD8wXG0aRLTcG29qVGw8CFfvCK7XVQ", 
     authDomain: "myfirstfirebaseproject-6da6c.firebaseapp.com", 
    }); 

    firebase.auth().onAuthStateChanged(user => { 
     if (user) { 
     this.isAuthenticated = true; 
     this.rootPage = HomePage; 
     } else { 
     this.isAuthenticated = false; 
     this.rootPage = Login; 
     } 
    }); 

    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(); 
     splashScreen.hide(); 
    }); 
    } 
} 
+1

app.module.tsを追加できますか? –

+0

アプリモジュールで何を追加する必要がありますか? – Jason

+0

あなたのプロジェクトには、app.module.tsに注入されたアングラファイアが含まれていますか? @surajが上で尋ねるように、このファイルの内容を貼り付けることができます –

答えて

0

設定が正しく設定されていません。このコードは、コンポーネントではなく、app.module.tsに置いてください。

import { 
    AngularFireModule, 
    AuthMethods, 
    AuthProviders 
} from 'angularfire2'; 

... 

@NgModule({ 
    bootstrap: [AppComponent], 
    declarations: [AppComponent], 
    imports: [ 
     AngularFireModule.initializeApp({ 
      apiKey: '<some-key>', 
      authDomain: '<some-project-authdomain>', 
      databaseURL: '<some-database-URL>', 
      storageBucket: '<some-storage-bucket>' 
     }, { 
      method: AuthMethods.Password, 
      provider: AuthProviders.Password 
     }), 
     BrowserModule, 
     ... 
    ] 
}) 
class AppModule {} 

platformBrowserDynamic().bootstrapModule(AppModule); 

これは、上記のコードが必要な場所です。プロバイダーが設定されていない場合は、引き続きエラーが発生します。

関連する問題