Skip to content

Commit 4b47014

Browse files
authored
Standlone DI in the docs (#3527)
1 parent 827a717 commit 4b47014

10 files changed

+132
-112
lines changed

docs/analytics.md

+14-20
Original file line numberDiff line numberDiff line change
@@ -9,45 +9,39 @@
99
Google Analytics is an app measurement solution, available at no charge, that provides insight on app usage and user engagement.
1010

1111
[Learn more](https://firebase.google.com/docs/analytics)
12+
1213
## Dependency Injection
1314

1415
As a prerequisite, ensure that `AngularFire` has been added to your project via
1516
```bash
1617
ng add @angular/fire
1718
```
1819

19-
Provide a Google Analytics instance in the application's `NgModule` (`app.module.ts`):
20+
Provide a Analytics instance in the application's `app.config.ts`:
2021

2122
```ts
22-
@NgModule({
23-
declarations: [
24-
...
25-
],
26-
imports: [
23+
import { provideFirebaseApp, initializeApp } from '@angular/fire/app';
24+
import { provideAnalytics, getAnalytics } from '@angular/fire/analytics';
25+
26+
export const appConfig: ApplicationConfig = {
27+
providers: [
28+
provideFirebaseApp(() => initializeApp({ ... })),
29+
provideAnalytics(() => getAnalytics()),
2730
...
28-
// App initialization
29-
provideFirebaseApp(() => initializeApp(environment.firebase)),
30-
provideAnalytics(() => getAnalytics())
3131
],
32-
providers: [],
33-
bootstrap: [AppComponent]
34-
})
35-
export class AppModule { }
32+
...,
33+
}
3634
```
3735

38-
In your component class, for example `user-profile.component.ts` import and inject `Firestore`:
36+
Next inject `Analytics` into your component:
3937

4038
```typescript
4139
import { Component, inject } from '@angular/core';
4240
import { Analytics } from '@angular/fire/analytics';
4341

44-
@Component({
45-
standalone: true,
46-
selector: 'app-user-profile',
47-
...
48-
})
42+
@Component({ ... })
4943
export class UserProfileComponent {
50-
private analytics: Analytics = inject(Analytics);
44+
private analytics = inject(Analytics);
5145
...
5246
}
5347
```

docs/app-check.md

+12-9
Original file line numberDiff line numberDiff line change
@@ -11,36 +11,39 @@ App Check helps protect your API resources from abuse by preventing unauthorized
1111
[Learn More](https://firebase.google.com/docs/app-check)
1212

1313
## Dependency Injection
14+
1415
As a prerequisite, ensure that `AngularFire` has been added to your project via
1516
```bash
1617
ng add @angular/fire
1718
```
1819

19-
Provide an App Check instance and configuration in the application's `NgModule` (`app.module.ts`):
20+
Provide a App Check instance in the application's `app.config.ts`:
2021

2122
```ts
2223
import { provideFirebaseApp, initializeApp } from '@angular/fire/app';
23-
import { provideAppCheck } from '@angular/fire/app-check';
24+
import { provideAppCheck, initializeAppCheck, ReCaptchaV3Provider } from '@angular/fire/app-check';
2425

25-
@NgModule({
26-
imports: [
27-
provideFirebaseApp(() => initializeApp(environment.firebase)),
26+
export const appConfig: ApplicationConfig = {
27+
providers: [
28+
provideFirebaseApp(() => initializeApp({ ... })),
2829
provideAppCheck(() => initializeAppCheck(getApp(), {
2930
provider: new ReCaptchaV3Provider(/* configuration */),
30-
})),
31-
]
31+
})),
32+
...
33+
],
34+
...
3235
})
3336
```
3437

35-
Next inject it into your component:
38+
Next inject `AppCheck` it into your component:
3639

3740
```ts
3841
import { Component, inject} from '@angular/core';
3942
import { AppCheck } from '@angular/fire/app-check';
4043

4144
@Component({ ... })
4245
export class AppCheckComponent {
43-
private appCheck: AppCheck = inject(AppCheck);
46+
private appCheck = inject(AppCheck);
4447
...
4548
}
4649
```

docs/auth.md

+11-9
Original file line numberDiff line numberDiff line change
@@ -20,29 +20,31 @@ As a prerequisite, ensure that `AngularFire` has been added to your project via
2020
ng add @angular/fire
2121
```
2222

23-
Provide an auth instance in the application's `NgModule` (`app.module.ts`):
23+
Provide a Auth instance in the application's `app.config.ts`:
2424

2525
```ts
2626
import { provideFirebaseApp, initializeApp } from '@angular/fire/app';
27-
import { getAuth, provideAuth } from '@angular/fire/auth';
27+
import { provideAuth, getAuth } from '@angular/fire/auth';
2828

29-
@NgModule({
30-
imports: [
31-
provideFirebaseApp(() => initializeApp(environment.firebase)),
29+
export const appConfig: ApplicationConfig = {
30+
providers: [
31+
provideFirebaseApp(() => initializeApp({ ... })),
3232
provideAuth(() => getAuth()),
33-
]
33+
...
34+
],
35+
...
3436
})
3537
```
3638

37-
Next inject it into your component:
39+
Next inject `Auth` into your component:
3840

3941
```ts
4042
import { Component, inject} from '@angular/core';
4143
import { Auth } from '@angular/fire/auth';
4244

4345
@Component({ ... })
4446
export class LoginComponent {
45-
private auth: Auth = inject(Auth);
47+
private auth = inject(Auth);
4648
...
4749
}
4850
```
@@ -51,7 +53,7 @@ export class LoginComponent {
5153

5254
AngularFire wraps the Firebase JS SDK to ensure proper functionality in Angular, while providing the same API.
5355

54-
Update the imports from `import { ... } from 'firebase/auth'` to `import { ... } from '@angular/fire/auth'` and follow the offical documentation.
56+
Update the imports from `import { ... } from 'firebase/auth'` to `import { ... } from '@angular/fire/auth'` and follow the official documentation.
5557

5658
[Getting Started](https://firebase.google.com/docs/auth/web/start) | [API Reference](https://firebase.google.com/docs/reference/js/auth)
5759

docs/database.md

+12-12
Original file line numberDiff line numberDiff line change
@@ -17,32 +17,32 @@ As a prerequisite, ensure that `AngularFire` has been added to your project via
1717
ng add @angular/fire
1818
```
1919

20-
Provide an RTBD instance in the application's `NgModule` (`app.module.ts`):
20+
Provide a Database instance in the application's `app.config.ts`:
2121

2222
```ts
2323
import { provideFirebaseApp, initializeApp } from '@angular/fire/app';
24-
import { getDatabase, provideDatabase } from '@angular/fire/database';
24+
import { provideDatabase, getDatabase } from '@angular/fire/database';
2525

26-
@NgModule({
27-
imports: [
28-
provideFirebaseApp(() => initializeApp(environment.firebase)),
26+
export const appConfig: ApplicationConfig = {
27+
providers: [
28+
provideFirebaseApp(() => initializeApp({ ... })),
2929
provideDatabase(() => getDatabase()),
30-
]
30+
...
31+
],
32+
...
3133
})
3234
```
3335

34-
Next inject it into your component:
36+
Next inject `Database` into your component:
3537

3638
```ts
3739
import { Component, inject } from '@angular/core';
3840
import { Database } from '@angular/fire/database';
3941

4042
@Component({...})
41-
extend class DepartmentComponent {
42-
private database: Database = inject(Database);
43-
44-
constructor() {
45-
}
43+
export class DepartmentComponent {
44+
private database = inject(Database);
45+
...
4646
}
4747
```
4848

docs/firestore.md

+14-22
Original file line numberDiff line numberDiff line change
@@ -18,39 +18,31 @@ As a prerequisite, ensure that `AngularFire` has been added to your project via
1818
```bash
1919
ng add @angular/fire
2020
```
21-
Provide a Firestore instance in the application's `NgModule` (`app.module.ts`):
21+
Provide a Firestore instance in the application's `app.config.ts`:
2222

23-
```typescript
24-
@NgModule({
25-
declarations: [
26-
...
27-
],
28-
imports: [
23+
```ts
24+
import { provideFirebaseApp, initializeApp } from '@angular/fire/app';
25+
import { provideFirestore, getFirestore } from '@angular/fire/firestore';
26+
27+
export const appConfig: ApplicationConfig = {
28+
providers: [
29+
provideFirebaseApp(() => initializeApp({ ... })),
30+
provideFirestore(() => getFirestore()),
2931
...
30-
// App initialization
31-
provideFirebaseApp(() => initializeApp(environment.firebase)),
32-
provideFirestore(() => getFirestore())
3332
],
34-
providers: [],
35-
bootstrap: [AppComponent]
36-
})
37-
export class AppModule { }
33+
...
34+
}
3835
```
3936

40-
41-
In your component class, for example `user-profile.component.ts` import and inject `Firestore`:
37+
Next inject `Firestore` into your component:
4238

4339
```typescript
4440
import { Component, inject } from '@angular/core';
4541
import { Firestore } from '@angular/fire/firestore';
4642

47-
@Component({
48-
standalone: true,
49-
selector: 'app-user-profile',
50-
...
51-
})
43+
@Component({ ... })
5244
export class UserProfileComponent {
53-
private firestore: Firestore = inject(Firestore);
45+
private firestore = inject(Firestore);
5446
...
5547
}
5648
```

docs/functions.md

+10-8
Original file line numberDiff line numberDiff line change
@@ -17,29 +17,31 @@ As a prerequisite, ensure that `AngularFire` has been added to your project via
1717
ng add @angular/fire
1818
```
1919

20-
Provide a Cloud Functions instance in the application's `NgModule` (`app.module.ts`):
20+
Provide a Cloud Functions instance in the application's `app.config.ts`:
2121

2222
```ts
2323
import { provideFirebaseApp, initializeApp } from '@angular/fire/app';
24-
import { getFunctions, provideFunctions } from '@angular/fire/functions';
24+
import { provideFunctions, getFunctions } from '@angular/fire/functions';
2525

26-
@NgModule({
27-
imports: [
28-
provideFirebaseApp(() => initializeApp(environment.firebase)),
26+
export const appConfig: ApplicationConfig = {
27+
providers: [
28+
provideFirebaseApp(() => initializeApp({ ... })),
2929
provideFunctions(() => getFunctions()),
30-
]
30+
...
31+
],
32+
...
3133
})
3234
```
3335

34-
Next inject it into your component:
36+
Next inject `Functions` into your component:
3537

3638
```ts
3739
import { Component, inject} from '@angular/core';
3840
import { Functions } from '@angular/fire/functions';
3941

4042
@Component({ ... })
4143
export class AppComponent {
42-
private functions: Functions = inject(Functions);
44+
private functions = inject(Functions);
4345
...
4446
}
4547
```

docs/messaging.md

+29-7
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,40 @@
88

99
Firebase FCM allows you to register devices with unique FCM tokens, that you can later programtically send notifications to using Firebase Cloud Functions. It is up to the application to update these tokens in Firebase if you want to use them in other layers of your application, i.e send a notification to all administrators, etc. In that case, you would likely want to store your fcm tokens on your user collection, or a sub collection or another collection with different permissions.
1010

11-
# Provide Messaging to your existing application
11+
## Dependency Injection
1212

13+
As a prerequisite, ensure that `AngularFire` has been added to your project via
14+
```bash
15+
ng add @angular/fire
1316
```
14-
import { getMessaging, provideMessaging } from "@angular/fire/messaging";
1517

16-
bootstrapApplication(AppComponent, {
18+
Provide a Cloud Messaging instance in the application's `app.config.ts`:
19+
20+
```ts
21+
import { provideFirebaseApp, initializeApp } from '@angular/fire/app';
22+
import { provideMessaging, getMessaging } from '@angular/fire/messaging';
23+
24+
export const appConfig: ApplicationConfig = {
1725
providers: [
18-
...,
19-
provideMessaging(() => getMessaging())
20-
),
26+
provideFirebaseApp(() => initializeApp({ ... })),
27+
provideMessaging(() => getMessaging()),
28+
...
2129
],
22-
});
30+
...
31+
})
32+
```
33+
34+
Next inject `Messaging` into your component:
35+
36+
```ts
37+
import { Component, inject} from '@angular/core';
38+
import { Messaging } from '@angular/fire/messaging';
39+
40+
@Component({ ... })
41+
export class AppComponent {
42+
private messaging = inject(Messaging);
43+
...
44+
}
2345
```
2446

2547
# Create a Firebase Messaging Service Worker

docs/performance.md

+10-8
Original file line numberDiff line numberDiff line change
@@ -17,29 +17,31 @@ As a prerequisite, ensure that `AngularFire` has been added to your project via
1717
ng add @angular/fire
1818
```
1919

20-
Provide a Performance instance and configuration in the application's `NgModule` (`app.module.ts`):
20+
Provide a Performance instance in the application's `app.config.ts`:
2121

2222
```ts
2323
import { provideFirebaseApp, initializeApp } from '@angular/fire/app';
24-
import { getPerformance, providePerformance} from '@angular/fire/performance';
24+
import { providePerformance, getPerformance } from '@angular/fire/performance';
2525

26-
@NgModule({
27-
imports: [
28-
provideFirebaseApp(() => initializeApp(environment.firebase)),
26+
export const appConfig: ApplicationConfig = {
27+
providers: [
28+
provideFirebaseApp(() => initializeApp({ ... })),
2929
providePerformance(() => getPerformance()),
30-
]
30+
...
31+
],
32+
...
3133
})
3234
```
3335

34-
Next inject it into your component:
36+
Next inject `Performance` into your component:
3537

3638
```ts
3739
import { Component, inject} from '@angular/core';
3840
import { Performance } from '@angular/fire/performance';
3941

4042
@Component({ ... })
4143
export class PerformanceComponent {
42-
private performance: Performance = inject(Performance);
44+
private performance = inject(Performance);
4345
...
4446
}
4547
```

0 commit comments

Comments
 (0)