@angular/fire 7.5.0 → 7.6.0-canary.b4c3da8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +85 -70
- package/bundles/angular-fire.umd.js +1 -1
- package/bundles/angular-fire.umd.js.map +1 -1
- package/docs/analytics.md +67 -0
- package/docs/app-check.md +53 -0
- package/docs/auth.md +165 -0
- package/docs/{analytics → compat/analytics}/getting-started.md +2 -0
- package/docs/{auth → compat/auth}/getting-started.md +2 -0
- package/docs/{auth → compat/auth}/router-guards.md +2 -0
- package/docs/{emulators → compat/emulators}/emulators.md +2 -0
- package/docs/{firestore → compat/firestore}/collections.md +2 -0
- package/docs/{firestore → compat/firestore}/documents.md +2 -0
- package/docs/{firestore → compat/firestore}/offline-data.md +2 -0
- package/docs/{firestore → compat/firestore}/querying-collections.md +2 -0
- package/docs/{functions → compat/functions}/functions.md +2 -0
- package/docs/{messaging → compat/messaging}/messaging.md +2 -0
- package/docs/{performance → compat/performance}/getting-started.md +2 -0
- package/docs/{remote-config → compat/remote-config}/getting-started.md +2 -0
- package/docs/{rtdb → compat/rtdb}/lists.md +2 -0
- package/docs/{rtdb → compat/rtdb}/objects.md +2 -0
- package/docs/{rtdb → compat/rtdb}/querying-lists.md +2 -0
- package/docs/{storage → compat/storage}/storage.md +2 -0
- package/docs/compat.md +70 -0
- package/docs/database.md +175 -0
- package/docs/firestore.md +148 -0
- package/docs/functions.md +52 -0
- package/docs/images/analytics-illo_1x.png +0 -0
- package/docs/images/auth-illo_1x.png +0 -0
- package/docs/images/cloud-messaging-illo_1x.png +0 -0
- package/docs/images/database-illo_1x.png +0 -0
- package/docs/images/firestore-illo_1x.png +0 -0
- package/docs/images/functions-illo_1x.png +0 -0
- package/docs/images/hosting-illo_1x.png +0 -0
- package/docs/images/performance-illo_1x.png +0 -0
- package/docs/images/reCAPTCHA-logo@1x.png +0 -0
- package/docs/images/remote-config-illo_1x.png +0 -0
- package/docs/images/storage-illo_1x.png +0 -0
- package/docs/install-and-setup.md +38 -85
- package/docs/messaging.md +25 -0
- package/docs/performance.md +57 -0
- package/docs/remote-config.md +53 -0
- package/docs/storage.md +90 -0
- package/esm2015/core.js +1 -1
- package/fesm2015/angular-fire.js +1 -1
- package/fesm2015/angular-fire.js.map +1 -1
- package/package.json +9 -10
- package/schematics/deploy/actions.js +23 -14
- package/schematics/firebaseTools.js +4 -2
- package/schematics/setup/index.js +58 -29
- package/schematics/setup/prompts.js +18 -46
- package/schematics/utils.js +32 -28
- package/docs/ionic/authentication.md +0 -104
- package/docs/ionic/cli.md +0 -218
- package/docs/ionic/v2.md +0 -531
- package/docs/ionic/v3.md +0 -705
- package/schematics/setup/ssr.js +0 -100
- package/schematics/setup/static.js +0 -78
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
> Cloud Firestore supports offline data persistence. This feature caches a copy of the Cloud Firestore data that your app is actively using, so your app can access the data when the device is offline. You can write, read, listen to, and query the cached data. When the device comes back online, Cloud Firestore synchronizes any local changes made by your app to the data stored remotely in Cloud Firestore.
|
|
4
4
|
|
|
5
|
+
> **NOTE**: [AngularFire has a new tree-shakable API](../../../README.md#developer-guide), you're looking at the documentation for the compatability version of the library. [See the v7 upgrade guide for more information on this change.](../../version-7-upgrade.md).
|
|
6
|
+
|
|
5
7
|
**Offline persistence is an experimental feature that is supported only by the Chrome, Safari, and Firefox web browsers.** If a user opens multiple browser tabs that point to the same Cloud Firestore database, and offline persistence is enabled, Cloud Firestore will work correctly only in the first tab.
|
|
6
8
|
|
|
7
9
|
## Enable Offline Data in AngularFirestore
|
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
> Firestore has [powerful querying syntax](https://firebase.google.com/docs/firestore/query-data/queries) and the `AngularFirestoreCollection` provides a thin wrapper around it. This keeps you from having to learn two query syntax systems.
|
|
4
4
|
If you know the [Firestore query API](https://firebase.google.com/docs/reference/js/firebase.firestore.Query) then you know how to query in AngularFirestore.
|
|
5
5
|
|
|
6
|
+
> **NOTE**: [AngularFire has a new tree-shakable API](../../../README.md#developer-guide), you're looking at the documentation for the compatability version of the library. [See the v7 upgrade guide for more information on this change.](../../version-7-upgrade.md).
|
|
7
|
+
|
|
6
8
|
## Creating a query with primitive/scalar values
|
|
7
9
|
|
|
8
10
|
Queries are created by building on the [`firebase.firestore.CollectionReference`](https://firebase.google.com/docs/reference/js/firebase.firestore.CollectionReference).
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
> The Cloud Functions for Firebase client SDKs let you call functions directly from a Firebase app. To call a function from your app in this way, write and deploy an HTTPS Callable function in Cloud Functions, and then add client logic to call the function from your app.
|
|
4
4
|
|
|
5
|
+
> **NOTE**: [AngularFire has a new tree-shakable API](../../../README.md#developer-guide), you're looking at the documentation for the compatability version of the library. [See the v7 upgrade guide for more information on this change.](../../version-7-upgrade.md).
|
|
6
|
+
|
|
5
7
|
### Import the `NgModule`
|
|
6
8
|
|
|
7
9
|
Cloud Functions for AngularFire is contained in the `@angular/fire/functions` module namespace. Import the `AngularFireFunctionsModule` in your `NgModule`. This sets up the `AngularFireFunction` service for dependency injection.
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
> The FCM JavaScript API lets you receive notification messages in web apps running in browsers that support the Push API.
|
|
4
4
|
|
|
5
|
+
> **NOTE**: [AngularFire has a new tree-shakable API](../../../README.md#developer-guide), you're looking at the documentation for the compatability version of the library. [See the v7 upgrade guide for more information on this change.](../../version-7-upgrade.md).
|
|
6
|
+
|
|
5
7
|
### AngularFireMessaging is not out-of-the-box compatible with the Angular Service Worker
|
|
6
8
|
|
|
7
9
|
If you are using the Angular Service Worker, you are not currently able to use AngularFireMessaging out-of-the-box.
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# Getting started with Performance Monitoring
|
|
2
2
|
|
|
3
|
+
> **NOTE**: [AngularFire has a new tree-shakable API](../../../README.md#developer-guide), you're looking at the documentation for the compatability version of the library. [See the v7 upgrade guide for more information on this change.](../../version-7-upgrade.md).
|
|
4
|
+
|
|
3
5
|
## Automatic page load tracing
|
|
4
6
|
|
|
5
7
|
Understand your Angular application's real-world performance with [Firebase Performance Monitoring](https://firebase.google.com/docs/perf-mon). Performance Monitoring automatically provides a trace for **page load** when you add `AngularFirePerformanceModule` into your App Module's imports.
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
`AngularFireRemoteConfig` dynamically imports the `firebase/remote-config` library on demand, provides convenience observables, pipes, and a promisified version of the [Firebase Remote Config SDK (`firebase.remoteConfig.RemoteConfig`)](https://firebase.google.com/docs/reference/js/firebase.remoteconfig.RemoteConfig).
|
|
4
4
|
|
|
5
|
+
> **NOTE**: [AngularFire has a new tree-shakable API](../../../README.md#developer-guide), you're looking at the documentation for the compatability version of the library. [See the v7 upgrade guide for more information on this change.](../../version-7-upgrade.md).
|
|
6
|
+
|
|
5
7
|
### API:
|
|
6
8
|
|
|
7
9
|
```ts
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# 3. Retrieving data as lists
|
|
2
2
|
|
|
3
|
+
> **NOTE**: [AngularFire has a new tree-shakable API](../../../README.md#developer-guide), you're looking at the documentation for the compatability version of the library. [See the v7 upgrade guide for more information on this change.](../../version-7-upgrade.md).
|
|
4
|
+
|
|
3
5
|
> AngularFire synchronizes data as lists using the `AngularFireList` service.
|
|
4
6
|
|
|
5
7
|
The `AngularFireList` service is not created by itself, but through the `AngularFireDatabase` service.
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# 2. Retrieving data as objects
|
|
2
2
|
|
|
3
|
+
> **NOTE**: [AngularFire has a new tree-shakable API](../../../README.md#developer-guide), you're looking at the documentation for the compatability version of the library. [See the v7 upgrade guide for more information on this change.](../../version-7-upgrade.md).
|
|
4
|
+
|
|
3
5
|
> The `AngularFireObject` is a service for manipulating and streaming object data.
|
|
4
6
|
|
|
5
7
|
The `AngularFireObject` service is not created by itself, but through the `AngularFireDatabase` service.
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# 4. Querying lists
|
|
2
2
|
|
|
3
|
+
> **NOTE**: [AngularFire has a new tree-shakable API](../../../README.md#developer-guide), you're looking at the documentation for the compatability version of the library. [See the v7 upgrade guide for more information on this change.](../../version-7-upgrade.md).
|
|
4
|
+
|
|
3
5
|
## Creating a query with primitive/scalar values
|
|
4
6
|
|
|
5
7
|
Queries are created by building on the [`firebase.database.Reference`](https://firebase.google.com/docs/reference/js/firebase.database.Reference).
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
> Cloud Storage is designed to help you quickly and easily store and serve user-generated content, such as photos and videos.
|
|
4
4
|
|
|
5
|
+
> **NOTE**: [AngularFire has a new tree-shakable API](../../../README.md#developer-guide), you're looking at the documentation for the compatability version of the library. [See the v7 upgrade guide for more information on this change.](../../version-7-upgrade.md).
|
|
6
|
+
|
|
5
7
|
### Import the `NgModule`
|
|
6
8
|
|
|
7
9
|
Cloud Storage for AngularFire is contained in the `@angular/fire/storage` module namespace. Import the `AngularFireStorageModule` in your `NgModule`. This sets up the `AngularFireStorage` service for dependency injection.
|
package/docs/compat.md
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# AngularFire
|
|
2
|
+
The official [Angular](https://angular.io/) library for [Firebase](https://firebase.google.com/).
|
|
3
|
+
|
|
4
|
+
<strong><pre>ng add @angular/fire</pre></strong>
|
|
5
|
+
|
|
6
|
+
## Compatibility Developer Guide
|
|
7
|
+
|
|
8
|
+
AngularFire has a new tree-shakable API, you're looking at the documentation for the compatability version of the library. [Find the new developer guide here](../README.md#developer-guide).
|
|
9
|
+
|
|
10
|
+
[See the v7 upgrade guide for more information on this change.](version-7-upgrade.md).
|
|
11
|
+
|
|
12
|
+
### Monitor usage of your application in production
|
|
13
|
+
|
|
14
|
+
> `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](https://firebase.google.com/docs/analytics).
|
|
15
|
+
|
|
16
|
+
- [Getting started with Google Analytics](compat/analytics/getting-started.md)
|
|
17
|
+
|
|
18
|
+
### Interacting with your database(s)
|
|
19
|
+
|
|
20
|
+
Firebase offers two cloud-based, client-accessible database solutions that support realtime data syncing. [Learn about the differences between them in the Firebase Documentation](https://firebase.google.com/docs/firestore/rtdb-vs-firestore).
|
|
21
|
+
|
|
22
|
+
#### Cloud Firestore
|
|
23
|
+
|
|
24
|
+
> `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.
|
|
25
|
+
|
|
26
|
+
- [Documents](compat/firestore/documents.md)
|
|
27
|
+
- [Collections](compat/firestore/collections.md)
|
|
28
|
+
- [Querying Collections](compat/firestore/querying-collections.md)
|
|
29
|
+
- [Offline data](compat/firestore/offline-data.md)
|
|
30
|
+
|
|
31
|
+
#### Realtime Database
|
|
32
|
+
|
|
33
|
+
> `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.
|
|
34
|
+
|
|
35
|
+
- [Objects](compat/rtdb/objects.md)
|
|
36
|
+
- [Lists](compat/rtdb/lists.md)
|
|
37
|
+
- [Querying lists](compat/rtdb/querying-lists.md)
|
|
38
|
+
|
|
39
|
+
### Authenticate users
|
|
40
|
+
|
|
41
|
+
- [Getting started with Firebase Authentication](acompat/uth/getting-started.md)
|
|
42
|
+
- [Route users with AngularFire guards](compat/auth/router-guards.md)
|
|
43
|
+
|
|
44
|
+
### Local Emulator Suite
|
|
45
|
+
|
|
46
|
+
- [Getting started with Firebase Emulator Suite](compat/emulators/emulators.md)
|
|
47
|
+
|
|
48
|
+
### Upload files
|
|
49
|
+
|
|
50
|
+
- [Getting started with Cloud Storage](compat/storage/storage.md)
|
|
51
|
+
|
|
52
|
+
### Receive push notifications
|
|
53
|
+
|
|
54
|
+
- [Getting started with Firebase Messaging](compat/messaging/messaging.md)
|
|
55
|
+
|
|
56
|
+
### **BETA:** Change behavior and appearance of your application without deploying
|
|
57
|
+
|
|
58
|
+
> 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](https://firebase.google.com/docs/remote-config).
|
|
59
|
+
|
|
60
|
+
- [Getting started with Remote Config](compat/remote-config/getting-started.md)
|
|
61
|
+
|
|
62
|
+
### Monitor your application performance in production
|
|
63
|
+
|
|
64
|
+
> 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](https://firebase.google.com/docs/perf-mon).
|
|
65
|
+
|
|
66
|
+
- [Getting started with Performance Monitoring](compat/performance/getting-started.md)
|
|
67
|
+
|
|
68
|
+
### Directly call Cloud Functions
|
|
69
|
+
|
|
70
|
+
- [Getting started with Callable Functions](compat/functions/functions.md)
|
package/docs/database.md
ADDED
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
<img align="right" width="30%" src="images/database-illo_1x.png">
|
|
2
|
+
|
|
3
|
+
<small>
|
|
4
|
+
<a href="https://github.com/angular/angularfire">AngularFire</a> ❱ <a href="../README.md#developer-guide">Developer Guide</a> ❱ Realtime Database
|
|
5
|
+
</small>
|
|
6
|
+
|
|
7
|
+
# Realtime Database
|
|
8
|
+
|
|
9
|
+
Store and sync data with our NoSQL cloud database. Data is synced across all clients in realtime, and remains available when your app goes offline.
|
|
10
|
+
|
|
11
|
+
The Firebase Realtime Database is a cloud-hosted database. Data is stored as JSON and synchronized in realtime to every connected client. When you build cross-platform apps with our iOS, Android, and JavaScript SDKs, all of your clients share one Realtime Database instance and automatically receive updates with the newest data. [Learn more about the Realtime Database](https://firebase.google.com/docs/database).
|
|
12
|
+
|
|
13
|
+
## Dependency Injection
|
|
14
|
+
|
|
15
|
+
As a prerequisite, ensure that `AngularFire` has been added to your project via
|
|
16
|
+
```bash
|
|
17
|
+
ng add @angular/fire
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Provide an RTBD instance in the application's `NgModule` (`app.module.ts`):
|
|
21
|
+
|
|
22
|
+
```ts
|
|
23
|
+
import { provideFirebaseApp, initializeApp } from '@angular/fire/app';
|
|
24
|
+
import { getDatabase, provideDatabase } from '@angular/fire/database';
|
|
25
|
+
|
|
26
|
+
@NgModule({
|
|
27
|
+
imports: [
|
|
28
|
+
provideFirebaseApp(() => initializeApp(environment.firebase)),
|
|
29
|
+
provideDatabase(() => getDatabase()),
|
|
30
|
+
]
|
|
31
|
+
})
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Next inject it into your component:
|
|
35
|
+
|
|
36
|
+
```ts
|
|
37
|
+
import { Component, inject } from '@angular/core';
|
|
38
|
+
import { Database } from '@angular/fire/database';
|
|
39
|
+
|
|
40
|
+
@Component({...})
|
|
41
|
+
extend class DepartmentComponent {
|
|
42
|
+
private database: Database = inject(Database);
|
|
43
|
+
|
|
44
|
+
constructor() {
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Firebase API
|
|
50
|
+
|
|
51
|
+
AngularFire wraps the Firebase JS SDK to ensure proper functionality in Angular, while providing the same API.
|
|
52
|
+
|
|
53
|
+
Just change your imports from `import { ... } from 'firebase/database'` to `import { ... } from '@angular/fire/database'` and follow the offical documentation.
|
|
54
|
+
|
|
55
|
+
[Getting Started](https://firebase.google.com/docs/database/web/start) | [API Reference](https://firebase.google.com/docs/reference/js/database)
|
|
56
|
+
|
|
57
|
+
## Convenience observables
|
|
58
|
+
|
|
59
|
+
AngularFire provides observables to allow convenient use of the Realtime Database with RXJS.
|
|
60
|
+
|
|
61
|
+
### `object`
|
|
62
|
+
|
|
63
|
+
The `object()` function creates an observable that emits object changes.
|
|
64
|
+
|
|
65
|
+
| | |
|
|
66
|
+
|-----------------|------------------------------------------|
|
|
67
|
+
| **function** | `object(ref)` |
|
|
68
|
+
| **params** | ref: `Reference` |
|
|
69
|
+
| **return** | `Observable<QueryChange>` |
|
|
70
|
+
|
|
71
|
+
### `objectVal`
|
|
72
|
+
|
|
73
|
+
The `objectVal` function creates an observable that emits an array of object values, optionally with a mapped key.
|
|
74
|
+
|
|
75
|
+
| | |
|
|
76
|
+
|-----------------|-------------------------------------------------------|
|
|
77
|
+
| **function** | `objectVal(query, options?)` |
|
|
78
|
+
| **params** | query: `Reference\|Query`, options?: { keyField?: `string` } |
|
|
79
|
+
| **return** | `Observable<T>` |
|
|
80
|
+
|
|
81
|
+
### `list`
|
|
82
|
+
|
|
83
|
+
The `list()` function creates an observable that emits a sorted array for each child event change. The optional `events` parameter will filter which child events populate the array.
|
|
84
|
+
|
|
85
|
+
| | |
|
|
86
|
+
|-----------------|-------------------------------------------------------|
|
|
87
|
+
| **function** | `list(ref, options?)` |
|
|
88
|
+
| **params** | ref: `Reference\|Query`, options?: { events?: `ListenEvent[]` } |
|
|
89
|
+
| **return** | `Observable<QueryChange[]>` |
|
|
90
|
+
|
|
91
|
+
### `listVal`
|
|
92
|
+
|
|
93
|
+
The `listVal()` function creates an observable that emits an object mapped to its value, and optionally its key.
|
|
94
|
+
|
|
95
|
+
| | |
|
|
96
|
+
|-----------------|-------------------------------------------------------|
|
|
97
|
+
| **function** | `listVal(query, options?)` |
|
|
98
|
+
| **params** | ref: `Reference\|Query`, options?: { keyField?: `string` } |
|
|
99
|
+
| **return** | `Observable<T \| null>` |
|
|
100
|
+
|
|
101
|
+
### `stateChanges`
|
|
102
|
+
|
|
103
|
+
The `stateChanges()` function creates an observable that emits each time a change occurs at the reference or query passed. This is useful for tracking the changes in your list. The optional `events` parameter will filter which child events populate the array.
|
|
104
|
+
|
|
105
|
+
| | |
|
|
106
|
+
|-----------------|------------------------------------------------------|
|
|
107
|
+
| **function** | `stateChanges(ref, options?)` |
|
|
108
|
+
| **params** | ref: `Reference\|Query`, options:? { events?: `ListenEvent[]` } |
|
|
109
|
+
| **return** | `Observable<QueryChange>` |
|
|
110
|
+
|
|
111
|
+
### `auditTrail`
|
|
112
|
+
|
|
113
|
+
The `auditTrail()` function creates an observable that emits the entire state trail. This is useful for debugging or replaying the state of a list in your app. The optional `events` parameter will filter which child events populate the array.
|
|
114
|
+
|
|
115
|
+
| | |
|
|
116
|
+
|-----------------|------------------------------------------------------|
|
|
117
|
+
| **function** | `auditTrail(ref, options?)` |
|
|
118
|
+
| **params** | ref: `Reference\|Query`, options?: { events?: `ListenEvent[]` } |
|
|
119
|
+
| **return** | `Observable<QueryChange[]>` |
|
|
120
|
+
|
|
121
|
+
### `fromRef`
|
|
122
|
+
|
|
123
|
+
The `fromRef()` function creates an observable that emits reference changes.
|
|
124
|
+
|
|
125
|
+
| | |
|
|
126
|
+
|-----------------|------------------------------------------|
|
|
127
|
+
| **function** | `fromRef(ref, event)` |
|
|
128
|
+
| **params** | ref: `Reference\|Query`, event: `ListenEvent` |
|
|
129
|
+
| **return** | `Observable<QueryChange>` |
|
|
130
|
+
|
|
131
|
+
## Connecting the the emulator suite
|
|
132
|
+
|
|
133
|
+
```ts
|
|
134
|
+
import { connectDatabaseEmulator, getDatabase, provideDatabase } from '@angular/fire/database';
|
|
135
|
+
|
|
136
|
+
@NgModule({
|
|
137
|
+
imports: [
|
|
138
|
+
provideDatabase(() => {
|
|
139
|
+
const database = getDatabase();
|
|
140
|
+
connectDatabaseEmulator(database, 'localhost', 9000);
|
|
141
|
+
return database;
|
|
142
|
+
}),
|
|
143
|
+
]
|
|
144
|
+
})
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
## Working with multiple instances
|
|
148
|
+
|
|
149
|
+
```ts
|
|
150
|
+
import { provideFirebaseApp, FirebaseApp, initializeApp } from '@angular/fire/app';
|
|
151
|
+
import { getDatabase, provideDatabase } from '@angular/fire/database';
|
|
152
|
+
|
|
153
|
+
const DATABASE_SHARD_URLS = [
|
|
154
|
+
'https://FOO.firebaseio.com',
|
|
155
|
+
'https://BAR.firebaseio.com',
|
|
156
|
+
'https://BAZ.firebaseio.com',
|
|
157
|
+
];
|
|
158
|
+
|
|
159
|
+
@NgModule({
|
|
160
|
+
imports: [
|
|
161
|
+
provideFirebaseApp(() => initializeApp(environment.firebase)),
|
|
162
|
+
provideDatabase((app: FirebaseApp) => getDatabase(app, DATABASE_SHARD_URLS[0])),
|
|
163
|
+
provideDatabase((app: FirebaseApp) => getDatabase(app, DATABASE_SHARD_URLS[1])),
|
|
164
|
+
provideDatabase((app: FirebaseApp) => getDatabase(app, DATABASE_SHARD_URLS[2])),
|
|
165
|
+
]
|
|
166
|
+
})
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
```ts
|
|
170
|
+
import { DatabaseInstances } from '@angular/fire/database';
|
|
171
|
+
|
|
172
|
+
constructor(databases: DatabaseInstances) {
|
|
173
|
+
// databases => Database[]
|
|
174
|
+
}
|
|
175
|
+
```
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
<img align="right" width="30%" src="images/firestore-illo_1x.png">
|
|
2
|
+
|
|
3
|
+
<small>
|
|
4
|
+
<a href="https://github.com/angular/angularfire">AngularFire</a> ❱ <a href="../README.md#developer-guide">Developer Guide</a> ❱ Realtime Cloud Firestore
|
|
5
|
+
</small>
|
|
6
|
+
|
|
7
|
+
# Cloud Firestore
|
|
8
|
+
|
|
9
|
+
Cloud Firestore is a flexible, scalable NoSQL database for mobile, web, and server development from Firebase and Google Cloud. It keeps your data in sync across client apps through realtime listeners and offers offline support for mobile and web so you can build responsive apps that work regardless of network latency or Internet connectivity.
|
|
10
|
+
|
|
11
|
+
[Learn more](https://firebase.google.com/docs/firestore)
|
|
12
|
+
|
|
13
|
+
Cloud Firestore is the API that gives your application access to your database in the cloud or locally in your [emulator](https://firebase.google.com/docs/emulator-suite).
|
|
14
|
+
|
|
15
|
+
## Dependency Injection
|
|
16
|
+
|
|
17
|
+
As a prerequisite, ensure that `AngularFire` has been added to your project via
|
|
18
|
+
```bash
|
|
19
|
+
ng add @angular/fire
|
|
20
|
+
```
|
|
21
|
+
Provide a Firestore instance in the application's `NgModule` (`app.module.ts`):
|
|
22
|
+
|
|
23
|
+
```typescript
|
|
24
|
+
@NgModule({
|
|
25
|
+
declarations: [
|
|
26
|
+
...
|
|
27
|
+
],
|
|
28
|
+
imports: [
|
|
29
|
+
...
|
|
30
|
+
// App initialization
|
|
31
|
+
provideFirebaseApp(() => initializeApp(environment.firebase)),
|
|
32
|
+
provideFirestore(() => getFirestore())
|
|
33
|
+
],
|
|
34
|
+
providers: [],
|
|
35
|
+
bootstrap: [AppComponent]
|
|
36
|
+
})
|
|
37
|
+
export class AppModule { }
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
In your component class, for example `user-profile.component.ts` import and inject `Firestore`:
|
|
42
|
+
|
|
43
|
+
```typescript
|
|
44
|
+
import { Component, inject } from '@angular/core';
|
|
45
|
+
import { Firestore } from '@angular/fire/firestore';
|
|
46
|
+
|
|
47
|
+
@Component({
|
|
48
|
+
standalone: true,
|
|
49
|
+
selector: 'app-user-profile',
|
|
50
|
+
...
|
|
51
|
+
})
|
|
52
|
+
export class UserProfileComponent {
|
|
53
|
+
private firestore: Firestore = inject(Firestore);
|
|
54
|
+
...
|
|
55
|
+
}
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Firebase API
|
|
59
|
+
With the reference to Cloud Firestore available in a component it is now possible to connect read from and write to the database.
|
|
60
|
+
|
|
61
|
+
### Reading data
|
|
62
|
+
In Cloud Firestore data is stored in `documents` and `documents` are stored in `collections`. The path to data follows `<collection_name>/<document_id>` and continues if there are subcollections. For example, `"users/ABC1245/posts/XYZ6789"` represents:
|
|
63
|
+
* `users` collection
|
|
64
|
+
* document id `ABC12345`
|
|
65
|
+
* `posts` collection
|
|
66
|
+
* document id `XYZ6789`
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
Let's explore reading data in Angular using the `collection` and `collectionData` functions.
|
|
70
|
+
|
|
71
|
+
In `user-profile.component.ts`:
|
|
72
|
+
|
|
73
|
+
```typescript
|
|
74
|
+
import { Firestore, collection, collectionData} from '@angular/fire/firestore';
|
|
75
|
+
import { Component, inject } from '@angular/core';
|
|
76
|
+
|
|
77
|
+
@Component ({
|
|
78
|
+
selector: 'app-user-profile',
|
|
79
|
+
standalone: true,
|
|
80
|
+
...
|
|
81
|
+
})
|
|
82
|
+
export class UserProfileComponent {
|
|
83
|
+
private firestore: Firestore = inject(Firestore); // inject Cloud Firestore
|
|
84
|
+
users$: Observable<UserProfile[]>;
|
|
85
|
+
|
|
86
|
+
constructor() {
|
|
87
|
+
// get a reference to the user-profile collection
|
|
88
|
+
const userProfileCollection = collection(this.firestore, 'users');
|
|
89
|
+
|
|
90
|
+
// get documents (data) from the collection using collectionData
|
|
91
|
+
this.users$ = collectionData(userProfileCollection) as Observable<UserProfile[]>;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
export Interface UserProfile {
|
|
95
|
+
username: string;
|
|
96
|
+
}
|
|
97
|
+
```
|
|
98
|
+
`collectionData` returns an `observable` that can we can use to display the data in the template. In `user-profile.component.html`:
|
|
99
|
+
|
|
100
|
+
```html
|
|
101
|
+
<section>
|
|
102
|
+
<h1>User Profiles</h1>
|
|
103
|
+
<ul>
|
|
104
|
+
<li *ngFor="let user of users$ | async">
|
|
105
|
+
{{user.username}}
|
|
106
|
+
</li>
|
|
107
|
+
</ul>
|
|
108
|
+
</section>
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
The `async` pipe handles unsubscribing from observables.
|
|
112
|
+
|
|
113
|
+
### Writing data
|
|
114
|
+
To write to Cloud Firestore use the `addDoc` function. It will create a new document at the path specified by the collection. In `user-profile.component.ts`, we'll update the code to add a new document on a `<button>` click.
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
```typescript
|
|
118
|
+
import { Firestore, collection, collectionData, addDoc} from '@angular/fire/firestore';
|
|
119
|
+
import { Component, inject } from '@angular/core';
|
|
120
|
+
|
|
121
|
+
@Component ({
|
|
122
|
+
selector: 'app-user-profile',
|
|
123
|
+
standalone: true,
|
|
124
|
+
...
|
|
125
|
+
})
|
|
126
|
+
export class UserProfileComponent {
|
|
127
|
+
private firestore: Firestore = inject(Firestore); // inject Cloud Firestore
|
|
128
|
+
users$: Observable<UserProfile[]>;
|
|
129
|
+
usersCollection: CollectionReference;
|
|
130
|
+
|
|
131
|
+
constructor() {...}
|
|
132
|
+
|
|
133
|
+
addUserProfile(username: string) {
|
|
134
|
+
if (!username) return;
|
|
135
|
+
|
|
136
|
+
addDoc(this.usersCollection, <UserProfile> { username }).then((documentReference: DocumentReference) => {
|
|
137
|
+
// the documentReference provides access to the newly created document
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
export Interface UserProfile {
|
|
142
|
+
username: string;
|
|
143
|
+
}
|
|
144
|
+
```
|
|
145
|
+
In the `addUserProfile` method we use a reference to the `this.usersCollection` and provide `UserProfile` data to the the `addDoc` function. `addDoc` returns a promise that can be used to respond to the successful addition of the data. Errors can also be caught here.
|
|
146
|
+
|
|
147
|
+
## Learn More
|
|
148
|
+
More information on API methods and other functions can be found on the [Firebase Official Docs](https://firebase.google.com/docs/reference/js/firestore_)
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
<img align="right" width="30%" src="images/functions-illo_1x.png">
|
|
2
|
+
|
|
3
|
+
<small>
|
|
4
|
+
<a href="https://github.com/angular/angularfire">AngularFire</a> ❱ <a href="../README.md#developer-guide">Developer Guide</a> ❱ Realtime Cloud Functions
|
|
5
|
+
</small>
|
|
6
|
+
|
|
7
|
+
# Cloud Functions
|
|
8
|
+
|
|
9
|
+
The Cloud Functions for Firebase client SDKs let you call functions directly from a Firebase app. To call a function from your app in this way, write and deploy an HTTPS Callable function in Cloud Functions, and then add client logic to call the function from your app.
|
|
10
|
+
|
|
11
|
+
[Learn More](https://firebase.google.com/docs/functions/get-started)
|
|
12
|
+
|
|
13
|
+
## Dependency Injection
|
|
14
|
+
|
|
15
|
+
As a prerequisite, ensure that `AngularFire` has been added to your project via
|
|
16
|
+
```bash
|
|
17
|
+
ng add @angular/fire
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Provide a Cloud Functions instance in the application's `NgModule` (`app.module.ts`):
|
|
21
|
+
|
|
22
|
+
```ts
|
|
23
|
+
import { provideFirebaseApp, initializeApp } from '@angular/fire/app';
|
|
24
|
+
import { getFunctions, provideFunctions } from '@angular/fire/functions';
|
|
25
|
+
|
|
26
|
+
@NgModule({
|
|
27
|
+
imports: [
|
|
28
|
+
provideFirebaseApp(() => initializeApp(environment.firebase)),
|
|
29
|
+
provideFunctions(() => getFunctions()),
|
|
30
|
+
]
|
|
31
|
+
})
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Next inject it into your component:
|
|
35
|
+
|
|
36
|
+
```ts
|
|
37
|
+
import { Component, inject} from '@angular/core';
|
|
38
|
+
import { Functions } from '@angular/fire/functions';
|
|
39
|
+
|
|
40
|
+
@Component({ ... })
|
|
41
|
+
export class AppComponent {
|
|
42
|
+
private functions: Functions = inject(Functions);
|
|
43
|
+
...
|
|
44
|
+
}
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Firebase API
|
|
48
|
+
The [Firebase API for Cloud Functions documentation](https://firebase.google.com/docs/reference/js/functions) is available on the Firebase website.
|
|
49
|
+
|
|
50
|
+
## Convenience observables
|
|
51
|
+
|
|
52
|
+
More details coming soon.
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|