Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Standalone DI in the docs #3527

Merged
merged 1 commit into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 14 additions & 20 deletions docs/analytics.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,45 +9,39 @@
Google Analytics is an app measurement solution, available at no charge, that provides insight on app usage and user engagement.

[Learn more](https://firebase.google.com/docs/analytics)

## Dependency Injection

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

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

```ts
@NgModule({
declarations: [
...
],
imports: [
import { provideFirebaseApp, initializeApp } from '@angular/fire/app';
import { provideAnalytics, getAnalytics } from '@angular/fire/analytics';

export const appConfig: ApplicationConfig = {
providers: [
provideFirebaseApp(() => initializeApp({ ... })),
provideAnalytics(() => getAnalytics()),
...
// App initialization
provideFirebaseApp(() => initializeApp(environment.firebase)),
provideAnalytics(() => getAnalytics())
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
...,
}
```

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

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

@Component({
standalone: true,
selector: 'app-user-profile',
...
})
@Component({ ... })
export class UserProfileComponent {
private analytics: Analytics = inject(Analytics);
private analytics = inject(Analytics);
...
}
```
Expand Down
21 changes: 12 additions & 9 deletions docs/app-check.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,36 +11,39 @@ App Check helps protect your API resources from abuse by preventing unauthorized
[Learn More](https://firebase.google.com/docs/app-check)

## Dependency Injection

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

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

```ts
import { provideFirebaseApp, initializeApp } from '@angular/fire/app';
import { provideAppCheck } from '@angular/fire/app-check';
import { provideAppCheck, initializeAppCheck, ReCaptchaV3Provider } from '@angular/fire/app-check';

@NgModule({
imports: [
provideFirebaseApp(() => initializeApp(environment.firebase)),
export const appConfig: ApplicationConfig = {
providers: [
provideFirebaseApp(() => initializeApp({ ... })),
provideAppCheck(() => initializeAppCheck(getApp(), {
provider: new ReCaptchaV3Provider(/* configuration */),
})),
]
})),
...
],
...
})
```

Next inject it into your component:
Next inject `AppCheck` it into your component:

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

@Component({ ... })
export class AppCheckComponent {
private appCheck: AppCheck = inject(AppCheck);
private appCheck = inject(AppCheck);
...
}
```
Expand Down
20 changes: 11 additions & 9 deletions docs/auth.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,29 +20,31 @@ As a prerequisite, ensure that `AngularFire` has been added to your project via
ng add @angular/fire
```

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

```ts
import { provideFirebaseApp, initializeApp } from '@angular/fire/app';
import { getAuth, provideAuth } from '@angular/fire/auth';
import { provideAuth, getAuth } from '@angular/fire/auth';

@NgModule({
imports: [
provideFirebaseApp(() => initializeApp(environment.firebase)),
export const appConfig: ApplicationConfig = {
providers: [
provideFirebaseApp(() => initializeApp({ ... })),
provideAuth(() => getAuth()),
]
...
],
...
})
```

Next inject it into your component:
Next inject `Auth` into your component:

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

@Component({ ... })
export class LoginComponent {
private auth: Auth = inject(Auth);
private auth = inject(Auth);
...
}
```
Expand All @@ -51,7 +53,7 @@ export class LoginComponent {

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

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

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

Expand Down
24 changes: 12 additions & 12 deletions docs/database.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,32 +17,32 @@ As a prerequisite, ensure that `AngularFire` has been added to your project via
ng add @angular/fire
```

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

```ts
import { provideFirebaseApp, initializeApp } from '@angular/fire/app';
import { getDatabase, provideDatabase } from '@angular/fire/database';
import { provideDatabase, getDatabase } from '@angular/fire/database';

@NgModule({
imports: [
provideFirebaseApp(() => initializeApp(environment.firebase)),
export const appConfig: ApplicationConfig = {
providers: [
provideFirebaseApp(() => initializeApp({ ... })),
provideDatabase(() => getDatabase()),
]
...
],
...
})
```

Next inject it into your component:
Next inject `Database` into your component:

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

@Component({...})
extend class DepartmentComponent {
private database: Database = inject(Database);

constructor() {
}
export class DepartmentComponent {
private database = inject(Database);
...
}
```

Expand Down
36 changes: 14 additions & 22 deletions docs/firestore.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,39 +18,31 @@ As a prerequisite, ensure that `AngularFire` has been added to your project via
```bash
ng add @angular/fire
```
Provide a Firestore instance in the application's `NgModule` (`app.module.ts`):
Provide a Firestore instance in the application's `app.config.ts`:

```typescript
@NgModule({
declarations: [
...
],
imports: [
```ts
import { provideFirebaseApp, initializeApp } from '@angular/fire/app';
import { provideFirestore, getFirestore } from '@angular/fire/firestore';

export const appConfig: ApplicationConfig = {
providers: [
provideFirebaseApp(() => initializeApp({ ... })),
provideFirestore(() => getFirestore()),
...
// App initialization
provideFirebaseApp(() => initializeApp(environment.firebase)),
provideFirestore(() => getFirestore())
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
...
}
```


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

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

@Component({
standalone: true,
selector: 'app-user-profile',
...
})
@Component({ ... })
export class UserProfileComponent {
private firestore: Firestore = inject(Firestore);
private firestore = inject(Firestore);
...
}
```
Expand Down
18 changes: 10 additions & 8 deletions docs/functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,31 @@ As a prerequisite, ensure that `AngularFire` has been added to your project via
ng add @angular/fire
```

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

```ts
import { provideFirebaseApp, initializeApp } from '@angular/fire/app';
import { getFunctions, provideFunctions } from '@angular/fire/functions';
import { provideFunctions, getFunctions } from '@angular/fire/functions';

@NgModule({
imports: [
provideFirebaseApp(() => initializeApp(environment.firebase)),
export const appConfig: ApplicationConfig = {
providers: [
provideFirebaseApp(() => initializeApp({ ... })),
provideFunctions(() => getFunctions()),
]
...
],
...
})
```

Next inject it into your component:
Next inject `Functions` into your component:

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

@Component({ ... })
export class AppComponent {
private functions: Functions = inject(Functions);
private functions = inject(Functions);
...
}
```
Expand Down
36 changes: 29 additions & 7 deletions docs/messaging.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,40 @@

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.

# Provide Messaging to your existing application
## Dependency Injection

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

bootstrapApplication(AppComponent, {
Provide a Cloud Messaging instance in the application's `app.config.ts`:

```ts
import { provideFirebaseApp, initializeApp } from '@angular/fire/app';
import { provideMessaging, getMessaging } from '@angular/fire/messaging';

export const appConfig: ApplicationConfig = {
providers: [
...,
provideMessaging(() => getMessaging())
),
provideFirebaseApp(() => initializeApp({ ... })),
provideMessaging(() => getMessaging()),
...
],
});
...
})
```

Next inject `Messaging` into your component:

```ts
import { Component, inject} from '@angular/core';
import { Messaging } from '@angular/fire/messaging';

@Component({ ... })
export class AppComponent {
private messaging = inject(Messaging);
...
}
```

# Create a Firebase Messaging Service Worker
Expand Down
18 changes: 10 additions & 8 deletions docs/performance.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,31 @@ As a prerequisite, ensure that `AngularFire` has been added to your project via
ng add @angular/fire
```

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

```ts
import { provideFirebaseApp, initializeApp } from '@angular/fire/app';
import { getPerformance, providePerformance} from '@angular/fire/performance';
import { providePerformance, getPerformance } from '@angular/fire/performance';

@NgModule({
imports: [
provideFirebaseApp(() => initializeApp(environment.firebase)),
export const appConfig: ApplicationConfig = {
providers: [
provideFirebaseApp(() => initializeApp({ ... })),
providePerformance(() => getPerformance()),
]
...
],
...
})
```

Next inject it into your component:
Next inject `Performance` into your component:

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

@Component({ ... })
export class PerformanceComponent {
private performance: Performance = inject(Performance);
private performance = inject(Performance);
...
}
```
Expand Down
Loading
Loading