angular and firebase code example
Example 1: angular firebase
ng add @angular/fire
Example 2: angular firebase
npm install firebase @angular/fire
Example 3: angular firebase
import { AngularFirestore } from '@angular/fire/firestore';
@Component(...)
export class SomeComponent {
constructor(private db: AngularFirestore) {
const things = db.collection('things').valueChanges();
things.subscribe(console.log);
}
}
Example 4: angular firebase
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';
import { AngularFireModule } from '@angular/fire';
import { AngularFirestoreModule } from '@angular/fire/firestore';
import { AngularFireStorageModule } from '@angular/fire/storage';
import { AngularFireAuthModule } from '@angular/fire/auth';
const config = {
apiKey: '<your-key>',
authDomain: '<your-project-authdomain>',
databaseURL: '<your-database-URL>',
projectId: '<your-project-id>',
storageBucket: '<your-storage-bucket>',
messagingSenderId: '<your-messaging-sender-id>'
};
@NgModule({
imports: [
BrowserModule,
AngularFireModule.initializeApp(config),
AngularFirestoreModule,
AngularFireAuthModule,
AngularFireStorageModule
],
declarations: [ AppComponent ],
bootstrap: [ AppComponent ]
})
export class AppModule {}