Skip to content

Commit 351d609

Browse files
docs: fix broken code snippets in product guides
Several product-guide snippets did not compile or parse as written, so a reader copying them hit errors before reaching Firebase. - Close the appConfig object literal with } instead of }) in the App Check, Auth, Database, Functions, Messaging, Remote Config, Storage, and Performance guides. - Import ApplicationConfig in every appConfig snippet so the type annotation resolves. - App Check: import getApp, which the snippet calls. - Firestore: correct "export Interface" to "export interface" (twice), import Observable from rxjs, and import CollectionReference and DocumentReference. - Auth and Database: replace the NgModule emulator and multi-instance examples with the standalone appConfig form the rest of the guides teach, and inline the Firebase config instead of reading a no-longer-generated environment file. - Messaging: repair the FcmService example (declare message$, move its assignment into the constructor, make deleteToken async) and bump the service-worker CDN imports from 9.22.0 to 12.4.0 to match the firebase dependency.
1 parent 88c7b80 commit 351d609

9 files changed

Lines changed: 66 additions & 45 deletions

File tree

docs/app-check.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ ng add @angular/fire
2020
Provide a App Check instance in the application's `app.config.ts`:
2121

2222
```ts
23-
import { provideFirebaseApp, initializeApp } from '@angular/fire/app';
23+
import { ApplicationConfig } from '@angular/core';
24+
import { provideFirebaseApp, initializeApp, getApp } from '@angular/fire/app';
2425
import { provideAppCheck, initializeAppCheck, ReCaptchaV3Provider } from '@angular/fire/app-check';
2526

2627
export const appConfig: ApplicationConfig = {
@@ -32,7 +33,7 @@ export const appConfig: ApplicationConfig = {
3233
...
3334
],
3435
...
35-
})
36+
}
3637
```
3738

3839
Next inject `AppCheck` it into your component:

docs/auth.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ ng add @angular/fire
2323
Provide a Auth instance in the application's `app.config.ts`:
2424

2525
```ts
26+
import { ApplicationConfig } from '@angular/core';
2627
import { provideFirebaseApp, initializeApp } from '@angular/fire/app';
2728
import { provideAuth, getAuth } from '@angular/fire/auth';
2829

@@ -33,7 +34,7 @@ export const appConfig: ApplicationConfig = {
3334
...
3435
],
3536
...
36-
})
37+
}
3738
```
3839

3940
Next inject `Auth` into your component:
@@ -186,15 +187,18 @@ export class UserComponent implements OnDestroy {
186187
## Connecting the emulator suite
187188
188189
```ts
190+
import { ApplicationConfig } from '@angular/core';
191+
import { provideFirebaseApp, initializeApp } from '@angular/fire/app';
189192
import { connectAuthEmulator, getAuth, provideAuth } from '@angular/fire/auth';
190193

191-
@NgModule({
192-
imports: [
194+
export const appConfig: ApplicationConfig = {
195+
providers: [
196+
provideFirebaseApp(() => initializeApp({ ... })),
193197
provideAuth(() => {
194198
const auth = getAuth();
195199
connectAuthEmulator(auth, 'http://localhost:9099', { disableWarnings: true });
196200
return auth;
197201
}),
198202
]
199-
})
203+
}
200204
```

docs/database.md

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ ng add @angular/fire
2020
Provide a Database instance in the application's `app.config.ts`:
2121

2222
```ts
23+
import { ApplicationConfig } from '@angular/core';
2324
import { provideFirebaseApp, initializeApp } from '@angular/fire/app';
2425
import { provideDatabase, getDatabase } from '@angular/fire/database';
2526

@@ -30,7 +31,7 @@ export const appConfig: ApplicationConfig = {
3031
...
3132
],
3233
...
33-
})
34+
}
3435
```
3536

3637
Next inject `Database` into your component:
@@ -131,22 +132,26 @@ The `fromRef()` function creates an observable that emits reference changes.
131132
## Connecting to the emulator suite
132133

133134
```ts
135+
import { ApplicationConfig } from '@angular/core';
136+
import { provideFirebaseApp, initializeApp } from '@angular/fire/app';
134137
import { connectDatabaseEmulator, getDatabase, provideDatabase } from '@angular/fire/database';
135138

136-
@NgModule({
137-
imports: [
139+
export const appConfig: ApplicationConfig = {
140+
providers: [
141+
provideFirebaseApp(() => initializeApp({ ... })),
138142
provideDatabase(() => {
139143
const database = getDatabase();
140144
connectDatabaseEmulator(database, 'localhost', 9000);
141145
return database;
142146
}),
143147
]
144-
})
148+
}
145149
```
146150

147151
## Working with multiple instances
148152

149153
```ts
154+
import { ApplicationConfig } from '@angular/core';
150155
import { provideFirebaseApp, FirebaseApp, initializeApp } from '@angular/fire/app';
151156
import { getDatabase, provideDatabase } from '@angular/fire/database';
152157

@@ -156,14 +161,14 @@ const DATABASE_SHARD_URLS = [
156161
'https://BAZ.firebaseio.com',
157162
];
158163

159-
@NgModule({
160-
imports: [
161-
provideFirebaseApp(() => initializeApp(environment.firebase)),
164+
export const appConfig: ApplicationConfig = {
165+
providers: [
166+
provideFirebaseApp(() => initializeApp({ ... })),
162167
provideDatabase((app: FirebaseApp) => getDatabase(app, DATABASE_SHARD_URLS[0])),
163168
provideDatabase((app: FirebaseApp) => getDatabase(app, DATABASE_SHARD_URLS[1])),
164169
provideDatabase((app: FirebaseApp) => getDatabase(app, DATABASE_SHARD_URLS[2])),
165170
]
166-
})
171+
}
167172
```
168173

169174
```ts

docs/firestore.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ ng add @angular/fire
2121
Provide a Firestore instance in the application's `app.config.ts`:
2222

2323
```ts
24+
import { ApplicationConfig } from '@angular/core';
2425
import { provideFirebaseApp, initializeApp } from '@angular/fire/app';
2526
import { provideFirestore, getFirestore } from '@angular/fire/firestore';
2627

@@ -71,6 +72,7 @@ In `user-profile.component.ts`:
7172
```typescript
7273
import { Firestore, collection, collectionData} from '@angular/fire/firestore';
7374
import { Component, inject } from '@angular/core';
75+
import { Observable } from 'rxjs';
7476

7577
@Component ({
7678
selector: 'app-user-profile',
@@ -89,7 +91,7 @@ export class UserProfileComponent {
8991
this.users$ = collectionData(userProfileCollection) as Observable<UserProfile[]>;
9092
}
9193
}
92-
export Interface UserProfile {
94+
export interface UserProfile {
9395
username: string;
9496
}
9597
```
@@ -114,8 +116,9 @@ To write to Cloud Firestore use the `addDoc` function. It will create a new docu
114116

115117

116118
```typescript
117-
import { Firestore, collection, collectionData, addDoc} from '@angular/fire/firestore';
119+
import { Firestore, collection, collectionData, addDoc, CollectionReference, DocumentReference } from '@angular/fire/firestore';
118120
import { Component, inject } from '@angular/core';
121+
import { Observable } from 'rxjs';
119122

120123
@Component ({
121124
selector: 'app-user-profile',
@@ -137,7 +140,7 @@ export class UserProfileComponent {
137140
});
138141
}
139142
}
140-
export Interface UserProfile {
143+
export interface UserProfile {
141144
username: string;
142145
}
143146
```

docs/functions.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ ng add @angular/fire
2020
Provide a Cloud Functions instance in the application's `app.config.ts`:
2121

2222
```ts
23+
import { ApplicationConfig } from '@angular/core';
2324
import { provideFirebaseApp, initializeApp } from '@angular/fire/app';
2425
import { provideFunctions, getFunctions } from '@angular/fire/functions';
2526

@@ -30,7 +31,7 @@ export const appConfig: ApplicationConfig = {
3031
...
3132
],
3233
...
33-
})
34+
}
3435
```
3536

3637
Next inject `Functions` into your component:

docs/messaging.md

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ ng add @angular/fire
1818
Provide a Cloud Messaging instance in the application's `app.config.ts`:
1919

2020
```ts
21+
import { ApplicationConfig } from '@angular/core';
2122
import { provideFirebaseApp, initializeApp } from '@angular/fire/app';
2223
import { provideMessaging, getMessaging } from '@angular/fire/messaging';
2324

@@ -28,7 +29,7 @@ export const appConfig: ApplicationConfig = {
2829
...
2930
],
3031
...
31-
})
32+
}
3233
```
3334

3435
Next inject `Messaging` into your component:
@@ -55,10 +56,10 @@ There are two parts to Firebase Messaging, a Service Worker and the DOM API. Ang
5556
It may be wise to use file replacements or environments here for different environments
5657

5758
```
58-
// This sample application is using 9.22, make sure you are importing the same version
59+
// This sample application is using 12.4.0, make sure you are importing the same version
5960
60-
import { initializeApp } from "https://www.gstatic.com/firebasejs/9.22.0/firebase-app.js";
61-
import { getMessaging } from "https://www.gstatic.com/firebasejs/9.22.0/firebase-messaging-sw.js";
61+
import { initializeApp } from "https://www.gstatic.com/firebasejs/12.4.0/firebase-app.js";
62+
import { getMessaging } from "https://www.gstatic.com/firebasejs/12.4.0/firebase-messaging-sw.js";
6263
6364
const firebaseApp = initializeApp({
6465
apiKey: "",
@@ -83,16 +84,18 @@ import { Observable, tap } from "rxjs";
8384
providedIn: "root",
8485
})
8586
export class FcmService {
86-
constructor(private msg: Messaging){
87+
message$: Observable<unknown>;
88+
89+
constructor(private msg: Messaging) {
8790
Notification.requestPermission().then(
88-
(notificationPermissions: NotificationPermission) => {
89-
if (notificationPermissions === "granted") {
90-
console.log("Granted");
91-
}
92-
if (notificationPermissions === "denied") {
93-
console.log("Denied");
94-
}
95-
});
91+
(notificationPermissions: NotificationPermission) => {
92+
if (notificationPermissions === "granted") {
93+
console.log("Granted");
94+
}
95+
if (notificationPermissions === "denied") {
96+
console.log("Denied");
97+
}
98+
});
9699
navigator.serviceWorker
97100
.register("/assets/firebase-messaging-sw.js", {
98101
type: "module",
@@ -101,23 +104,24 @@ export class FcmService {
101104
getToken(this.msg, {
102105
vapidKey: `an optional key generated on Firebase for your fcm tokens`,
103106
serviceWorkerRegistration: serviceWorkerRegistration,
104-
}).then((x) => {
105-
console.log('my fcm token', x);
107+
}).then((token) => {
108+
console.log('my fcm token', token);
106109
// This is a good place to then store it on your database for each user
107110
});
108-
});
109-
}
110-
this.message$ = new Observable((sub) => onMessage(this.msg, (msg) =>
111-
sub.next(msg))).pipe(
112-
tap((msg) => {
113-
console.log("My Firebase Cloud Message", msg);
114-
})
111+
});
112+
this.message$ = new Observable((sub) =>
113+
onMessage(this.msg, (msg) => sub.next(msg))).pipe(
114+
tap((msg) => {
115+
console.log("My Firebase Cloud Message", msg);
116+
})
115117
);
116-
}
117-
deleteToken(){
118+
}
119+
120+
async deleteToken() {
118121
// We can also delete fcm tokens, make sure to also update this on your firestore db if you are storing them as well
119122
await deleteToken(this.msg);
120123
}
124+
}
121125
```
122126

123127
# Testing and Sending Notifications

docs/performance.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ ng add @angular/fire
2020
Provide a Performance instance in the application's `app.config.ts`:
2121

2222
```ts
23+
import { ApplicationConfig } from '@angular/core';
2324
import { provideFirebaseApp, initializeApp } from '@angular/fire/app';
2425
import { providePerformance, getPerformance } from '@angular/fire/performance';
2526

@@ -30,7 +31,7 @@ export const appConfig: ApplicationConfig = {
3031
...
3132
],
3233
...
33-
})
34+
}
3435
```
3536

3637
Next inject `Performance` into your component:

docs/remote-config.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ ng add @angular/fire
2020
Provide a Remote Config instance in the application's `app.config.ts`:
2121

2222
```ts
23+
import { ApplicationConfig } from '@angular/core';
2324
import { provideFirebaseApp, initializeApp } from '@angular/fire/app';
2425
import { provideRemoteConfig, getRemoteConfig } from '@angular/fire/remote-config';
2526

@@ -30,7 +31,7 @@ export const appConfig: ApplicationConfig = {
3031
...
3132
],
3233
...
33-
})
34+
}
3435
```
3536

3637
Next inject `RemoteConfig` into your component:

docs/storage.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ ng add @angular/fire
2222
Provide a Cloud Storage instance in the application's `app.config.ts`:
2323

2424
```ts
25+
import { ApplicationConfig } from '@angular/core';
2526
import { provideFirebaseApp, initializeApp } from '@angular/fire/app';
2627
import { provideStorage, getStorage } from '@angular/fire/storage';
2728

@@ -32,7 +33,7 @@ export const appConfig: ApplicationConfig = {
3233
...
3334
],
3435
...
35-
})
36+
}
3637
```
3738

3839
Next inject `Storage` into your component:

0 commit comments

Comments
 (0)