Security News
RubyGems.org Adds New Maintainer Role
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
@angular/fire
Advanced tools
@angular/fire is the official Angular library for Firebase. It provides a set of AngularFire modules that enable Angular applications to interact with Firebase services such as Firestore, Authentication, Storage, and more. This library simplifies the integration of Firebase with Angular applications, offering reactive and declarative APIs.
Firestore
This feature allows you to interact with Firestore, a NoSQL database provided by Firebase. The code sample demonstrates how to retrieve a collection of items from Firestore and subscribe to changes in real-time.
import { AngularFirestore } from '@angular/fire/compat/firestore';
constructor(private firestore: AngularFirestore) {}
getItems() {
return this.firestore.collection('items').valueChanges();
}
Authentication
This feature enables authentication functionalities such as signing in, signing out, and managing user sessions. The code sample shows how to sign in a user using email and password.
import { AngularFireAuth } from '@angular/fire/compat/auth';
constructor(private afAuth: AngularFireAuth) {}
login(email: string, password: string) {
return this.afAuth.signInWithEmailAndPassword(email, password);
}
Storage
This feature allows you to interact with Firebase Storage, which is used for storing and serving user-generated content such as images and videos. The code sample demonstrates how to upload a file to Firebase Storage.
import { AngularFireStorage } from '@angular/fire/compat/storage';
constructor(private storage: AngularFireStorage) {}
uploadFile(filePath: string, file: File) {
const fileRef = this.storage.ref(filePath);
return fileRef.put(file);
}
Realtime Database
This feature provides access to Firebase Realtime Database, a cloud-hosted NoSQL database that allows data to be stored and synchronized in real-time. The code sample shows how to retrieve a list of items from the Realtime Database.
import { AngularFireDatabase } from '@angular/fire/compat/database';
constructor(private db: AngularFireDatabase) {}
getItems() {
return this.db.list('items').valueChanges();
}
Analytics
This feature enables the use of Firebase Analytics to log events and track user interactions within your application. The code sample demonstrates how to log a custom event.
import { AngularFireAnalytics } from '@angular/fire/compat/analytics';
constructor(private analytics: AngularFireAnalytics) {}
logEvent(eventName: string, eventParams: any) {
this.analytics.logEvent(eventName, eventParams);
}
The 'firebase' package is the official Firebase JavaScript SDK. It provides comprehensive access to Firebase services but lacks the Angular-specific integrations and reactive APIs provided by @angular/fire. Developers using Angular would need to manually integrate Firebase services and manage state updates.
The 'reactfire' package is the official Firebase library for React. It offers similar functionalities to @angular/fire but is tailored for React applications. It provides hooks and components to easily integrate Firebase services with React's component-based architecture.
The 'vuefire' package is the official Firebase library for Vue.js. It provides bindings to integrate Firebase services with Vue.js applications, similar to how @angular/fire integrates with Angular. It offers Vue-specific features such as directives and plugins.
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.
import { provideFirebaseApp, getApp, initializeApp } from '@angular/fire/app';
import { getFirestore, provideFirestore } from '@angular/fire/firestore';
@NgModule({
imports: [
provideFirebaseApp(() => initializeApp({ ... })),
provideFirestore(() => getFirestore()),
],
...
})
export class AppModule { }
import { Firestore, collectionData, collection } from '@angular/fire/firestore';
import { Observable } from 'rxjs';
interface Item {
name: string,
...
};
@Component({
selector: 'app-root',
template: `
<ul>
<li *ngFor="let item of item$ | async">
{{ item.name }}
</li>
</ul>
`
})
export class AppComponent {
item$: Observable<Item[]>;
constructor(firestore: Firestore) {
const collection = collection(firestore, 'items');
this.item$ = collectionData(collection);
}
}
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.
Angular | Firebase | AngularFire |
---|---|---|
14 | 9 | ^7.4 |
13 | 9 | ^7.2 |
12 | 9 | ^7.0 |
12 | 7,8 | ^6.1.5 |
11 | 7,8 | ^6.1 |
10 | 8 | ^6.0.4 |
10 | 7 | ^6.0.3 |
9 | 8 | ^6.0.4 |
9 | 7 | ^6.0 |
Version combinations not documented here may work but are untested and you will see NPM peer warnings.
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:
API | Environments | Suggested Polyfill | License |
---|---|---|---|
Various ES5+ features | Safari < 10 | core-js/stable | MIT |
globalThis | Chrome < 71 Safari < 12.1 iOS < 12.2 Node < 12 | globalThis | MIT |
Proxy | Safari < 10 | proxy-polyfill | Apache 2.0 |
fetch | Safari < 10.1 iOS < 10.3 | cross-fetch | MIT |
Quickstart - Get your first application up and running by following our quickstart guide.
Stackblitz Template - Remember to set your Firebase configuration in app/app.module.ts
.
Upgrading to v7.0? Check out our guide.
We have three sample apps in this repository:
samples/compat
a kitchen sink application that demonstrates use of the "compatability" APIsamples/modular
a kitchen sink application that demonstrates the new tree-shakable APIsamples/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.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 best-effort basis by maintainers and other community members. If you are able to reproduce a problem with Firebase outside of AngularFire's implementation, please file an issue on the Firebase JS SDK or reach out to the personalized Firebase support channel.
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/*
).
AngularFireAnalytics
provides a convenient method of interacting with Google Analytics in your Angular application. The providedScreenTrackingService
andUserTrackingService
automatically log events when you're using the Angular Router or Firebase Authentication respectively. Learn more about Google Analytics.
Firebase offers two cloud-based, client-accessible database solutions that support realtime data syncing. Learn about the differences between them in the Firebase Documentation.
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.
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.
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.
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.
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.
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.
FAQs
Angular + Firebase = ❤️
The npm package @angular/fire receives a total of 56,842 weekly downloads. As such, @angular/fire popularity was classified as popular.
We found that @angular/fire demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.
Security News
Research
Socket's threat research team has detected five malicious npm packages targeting Roblox developers, deploying malware to steal credentials and personal data.