読者です 読者をやめる 読者になる 読者になる

Firebase for Ionic2(導入)

ionic2 備忘録

(自分用の記録)
1.ionic2のプロジェクトを作成
2.npmでFirebaseを入れる

npm install angularfire --save

3.app.module.ts

import { AngularFireModule } from 'angularfire2';

とFirebase consoleのウェブアプリにFirebaseを追加からConfig部分を f:id:NISHI3:20170216124736p:plain

export const firebaseConfig = {
    apiKey: "",
    authDomain: "",
    databaseURL: "",
    storageBucket: "",
    messagingSenderId: ""
};

と@NgModuleのimports内に

imports: [
    IonicModule.forRoot(MyApp),
    AngularFireModule.initializeApp(firebaseConfig)
  ],

導入終了

(Sample)

import { NgModule, ErrorHandler } from '@angular/core';
import { IonicApp, IonicModule, IonicErrorHandler } from 'ionic-angular';
import { MyApp } from './app.component';
import { HomePage } from '../pages/home/home';

import { AngularFireModule } from 'angularfire2';

export const firebaseConfig = {
    apiKey: "",
    authDomain: "",
    databaseURL: "",
    storageBucket: "",
    messagingSenderId: ""
};

@NgModule({
  declarations: [
    MyApp,
    HomePage
  ],
  imports: [
    IonicModule.forRoot(MyApp),
    AngularFireModule.initializeApp(firebaseConfig)
  ],
  bootstrap: [IonicApp],
  entryComponents: [
    MyApp,
    HomePage
  ],
  providers: [{provide: ErrorHandler, useClass: IonicErrorHandler}]
})
export class AppModule {}