Using Angular with Firebase

  • You can add your Firebase config object directly to your environment config
  • @angular/fire is the official integration package
  • You just import the base package and anything else you want to use
import {AngularFireModule} from '@angular/fire';
import {AngularFireAnalyticsModule} from '@angular/fire/analytics';
import {AngularFireAuthModule} from '@angular/fire/auth';
import {AngularFireDatabaseModule} from '@angular/fire/database';
import {environment} from 'src/environments/environment';
...
// in the NgModule imports
AngularFireModule.initializeApp(environment.firebase),
AngularFireAnalyticsModule,
AngularFireAuthModule,
AngularFireDatabaseModule,
fireAuth.onAuthStateChanged((user: User|null) => {
  if (!user) {
    fireAuth.signInWithPopup(new auth.GoogleAuthProvider());
  }
});