Angular Fire

The official Angular library for Firebase.

README

AngularFire

The official Angular library for Firebase.

ng add @angular/fire

AngularFire smooths over the rough edges an Angular developer might encounter when implementing the framework-agnostic Firebase JS SDK & aims to provide a more natural developer experience by conforming to Angular conventions.

- Dependency injection - Provide and Inject Firebase services in your components
- Zone.js wrappers - Stable zones allow proper functionality of service workers, forms, SSR, and pre-rendering
- Observable based - Utilize RxJS rather than callbacks for realtime streams
- NgRx friendly API - Integrate with NgRx using AngularFire's action based APIs.
- Lazy-loading - AngularFire dynamically imports much of Firebase, reducing time to load your app
- Deploy schematics - Get your Angular application deployed on Firebase Hosting with a single command
- Google Analytics - Zero-effort Angular Router awareness in Google Analytics
- Router Guards - Guard your Angular routes with built-in Firebase Authentication checks

Example use


  1. ```ts
  2. import { provideFirebaseApp, getApp, initializeApp } from '@angular/fire/app';
  3. import { getFirestore, provideFirestore } from '@angular/fire/firestore';

  4. @NgModule({
  5.   imports: [
  6.     provideFirebaseApp(() => initializeApp({ ... })),
  7.     provideFirestore(() => getFirestore()),
  8.   ],
  9.   ...
  10. })
  11. export class AppModule { }
  12. ```

  1. ```ts
  2. import { Firestore, collectionData, collection } from '@angular/fire/firestore';
  3. import { Observable } from 'rxjs';

  4. interface Item {
  5.   name: string,
  6.   ...
  7. };

  8. @Component({
  9.   selector: 'app-root',
  10.   template: `
  11.   <ul>
  12.     <li *ngFor="let item of item$ | async">
  13.       {{ item.name }}
  14.     </li>
  15.   </ul>
  16.   `
  17. })
  18. export class AppComponent {
  19.   item$: Observable<Item[]>;
  20.   constructor(firestore: Firestore) {
  21.     const collection = collection(firestore, 'items');
  22.     this.item$ = collectionData(collection);
  23.   }
  24. }
  25. ```

Compatibility


Angular and Firebase versions


AngularFire doesn't follow Angular's versioning as Firebase also has breaking changes throughout the year. Instead we try to maintain compatibility with both Firebase and Angular majors for as long as possible, only breaking when we need to support a new major of one or the other.

AngularFirebaseAngularFire
--------|----------|--------------|
159^7.5
149^7.4
139^7.2
129^7.0
127,8^6.1.5
117,8^6.1
108^6.0.4
107^6.0.3
98^6.0.4
97^6.0

Version combinations not documented here __may__ work but are untested and you will see NPM peer warnings.

Polyfills


Neither AngularFire or Firebase ship with polyfills. To have compatability across as wide-range of environments we suggest the following polyfills be added to your application:

APIEnvironmentsSuggestedLicense
|-----|--------------|--------------------|---------|
VariousSafari[`core-js/stable`](https://github.com/zloirock/core-js#readme)MIT
`globalThis`[Chrome[`globalThis`](https://github.com/es-shims/globalThis#readme)MIT
`Proxy`[Safari[`proxy-polyfill`](https://github.com/GoogleChrome/proxy-polyfill#readme)Apache
`fetch`[Safari[`cross-fetch`](https://github.com/lquixada/cross-fetch#readme)MIT

Resources


Quickstart - Get your first application up and running by following our quickstart guide.


Stackblitz Template - Remember to set your Firebase configuration inapp/app.module.ts.


Sample apps


We have three sample apps in this repository:

1. [samples/compat](samples/compat) a kitchen sink application that demonstrates use of the "compatability" API
1. [samples/modular](samples/modular) a kitchen sink application that demonstrates the new tree-shakable API
1. [samples/advanced](samples/advanced) the same app as samples/modular but demonstrates more advanced concepts such as Angular Universal state-transfer, dynamically importing Firebase feature modules, and Firestore data bundling.

Having troubles?


Get help on our Q&A board, the official Firebase Mailing List, the Firebase Community Slack (#angularfire2), the Angular Community Discord (#firebase), Gitter, the Firebase subreddit, or Stack Overflow.

NOTE: AngularFire is maintained by Googlers but is not a supported Firebase product. Questions on the mailing list and issues filed here are answered on a <strong>best-effort basis</strong> by maintainers and other community members. If you are able to reproduce a problem with Firebase <em>outside of AngularFire's implementation</em>, please file an issue on the Firebase JS SDK or reach out to the personalized Firebase support channel.


Developer Guide


AngularFire has a new tree-shakable API, however this is still under active development and documentation is in the works, so we suggest most developers stick with the Compatiability API for the time being. See the v7 upgrade guide for more information..

This developer guide assumes you're using the Compatiability API (@angular/fire/compat/*).

Monitor usage of your application in production


AngularFireAnalytics provides a convenient method of interacting with Google Analytics in your Angular application. The provided ScreenTrackingService and UserTrackingService automatically log events when you're using the Angular Router or Firebase Authentication respectively. Learn more about Google Analytics.



Interacting with your database(s)


Firebase offers two cloud-based, client-accessible database solutions that support realtime data syncing. Learn about the differences between them in the Firebase Documentation.

Cloud Firestore


AngularFirestore allows you to work with Cloud Firestore, the new flagship database for mobile app development. It improves on the successes of Realtime Database with a new, more intuitive data model. Cloud Firestore also features richer, faster queries and scales better than Realtime Database.



Realtime Database


AngularFireDatabase allows you to work with the Realtime Database, Firebase's original database. It's an efficient, low-latency solution for mobile apps that require synced states across clients in realtime.



Authenticate users



Local Emulator Suite



Upload files



Receive push notifications



BETA: Change behavior and appearance of your application without deploying


Firebase Remote Config is a cloud service that lets you change the behavior and appearance of your app without requiring users to download an app update. Learn more about Remote Config.



Monitor your application performance in production


Firebase Performance Monitoring is a service that helps you to gain insight into the performance characteristics of your iOS, Android, and web apps. Learn more about Performance Monitoring.



Directly call Cloud Functions



Deploying your application


Firebase Hosting is production-grade web content hosting for developers. With Hosting, you can quickly and easily deploy web apps and static content to a global content delivery network (CDN) with a single command.



Server-side rendering


Angular Universal is a technology that allows you to run your Angular application on a server. This allows you to generate your HTML in a process called server-side rendering (SSR). AngularFire is compatible with server-side rendering; allowing you to take advantage of the Search Engine Optimization, link previews, the performance gains granted by the technology, and more. Learn more about Angular Universal.



Ionic