Skip to content
Open
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
3 changes: 2 additions & 1 deletion docs/ai.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ As a prerequisite, ensure that `AngularFire` has been added to your project as d
Provide an AI instance in the application's `app.config.ts`:

```ts
import { ApplicationConfig } from '@angular/core';
import { provideFirebaseApp, initializeApp } from '@angular/fire/app';
import { provideAI, getAI } from '@angular/fire/ai';

Expand All @@ -26,7 +27,7 @@ export const appConfig: ApplicationConfig = {
provideAI(() => getAI()),
...
],
...,
...
}
```

Expand Down
5 changes: 4 additions & 1 deletion docs/analytics.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ As a prerequisite, ensure that `AngularFire` has been added to your project as d
Provide an Analytics instance in the application's `app.config.ts`:

```ts
import { ApplicationConfig } from '@angular/core';
import { provideFirebaseApp, initializeApp } from '@angular/fire/app';
import { provideAnalytics, getAnalytics } from '@angular/fire/analytics';

Expand All @@ -26,7 +27,7 @@ export const appConfig: ApplicationConfig = {
provideAnalytics(() => getAnalytics()),
...
],
...,
...
}
```

Expand All @@ -43,6 +44,8 @@ export class UserProfileComponent {
}
```

`Analytics` is `null` during server rendering, although its type says `Analytics`, so check it before use.

## Firebase API

AngularFire wraps the Firebase JS SDK to ensure proper functionality in Angular, while providing the same API.
Expand Down
17 changes: 0 additions & 17 deletions docs/compat/emulators/emulators.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,23 +117,6 @@ export class AppModule { }

The environment `useEmulators` flag is used to control whenever the app should connect to the emulators, which is usually done in non-production environments.

Also you can opt-in the new way of setting the Cloud Functions [origin](https://firebase.google.com/docs/functions/locations) in Firebase v8 by using the `NEW_ORIGIN_BEHAVIOR` token in conjuction with the already present `ORIGIN` token.

```ts
import { isDevMode, NgModule } from '@angular/core';
import { ORIGIN as FUNCTIONS_ORIGIN, NEW_ORIGIN_BEHAVIOR } from '@angular/fire/compat/functions';

@NgModule({
// ... Existing configuration
providers: [
// ... Existing Providers
{ provide: NEW_ORIGIN_BEHAVIOR, useValue: true },
{ provide: FUNCTIONS_ORIGIN, useFactory: () => isDevMode() ? undefined : location.origin },
]
})
export class AppModule { }
```

### 6.0.0 Method

With the exception of the Auth Emulator, the old way of setting the `host` and `port` for each emulator was done using a different set of tokens by passing the entire url path as string.
Expand Down
25 changes: 15 additions & 10 deletions docs/compat/functions/functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

> 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.

> **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).
> **NOTE**: [AngularFire has a new tree-shakable API](../../../README.md#developer-guide), you're looking at the documentation for the compatibility version of the library. [See the v7 upgrade guide for more information on this change.](../../version-7-upgrade.md).

### Import the `NgModule`

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.
Cloud Functions for AngularFire is contained in the `@angular/fire/compat/functions` module namespace. Import the `AngularFireFunctionsModule` in your `NgModule`. This sets up the `AngularFireFunctions` service for dependency injection.

```ts
import { BrowserModule } from '@angular/platform-browser';
Expand Down Expand Up @@ -53,25 +53,29 @@ AngularFireFunctions is super easy. You create a function on the server side and

| method | |
| ---------|--------------------|
| `httpCallable(name: string): (data: T) ` | Creates a callable function based on a function name. Returns a function that can create the observable of the http call. |
| `httpsCallable<T = any, R = any>(name: string, options?: HttpsCallableOptions): (data: T) => Observable<R>` | Creates a callable function based on a function name. Returns a function that can create the observable of the http call. |
```ts

import { AsyncPipe } from '@angular/common';
import { Component } from '@angular/core';
import { AngularFireFunctions } from '@angular/fire/compat/functions';
import { Observable } from 'rxjs';

@Component({
selector: 'app-root',
template: `{ data$ | async }`
imports: [AsyncPipe],
template: `{{ data$ | async }}`
})
export class AppComponent {
constructor(private fns: AngularFireFunctions) {
data$: Observable<any>;

constructor(private fns: AngularFireFunctions) {
const callable = fns.httpsCallable('my-fn-name');
this.data$ = callable({ name: 'some-data' });
}
}
```

Notice that calling `httpsCallable()` does not initiate the request. It creates a function, which when called creates an Observable, subscribe or convert it to a Promise to initiate the request.
Notice that calling `httpsCallable()` does not initiate the request. It creates a function, which when called creates an Observable. Subscribe to the Observable or convert it to a Promise to initiate the request.

## Configuration via Dependency Injection

Expand Down Expand Up @@ -145,11 +149,11 @@ To set this up, you first need to update your `hosting` section in `firebase.jso
}
```

Deploy your hosting project to the new settings go into effect, finally configure functions origin to point at your app domain:
Deploy your hosting project so the new settings go into effect, then configure the functions origin to point at your app domain:

```ts
import { NgModule } from '@angular/core';
import { AngularFireFunctionsModule, ORIGIN, NEW_ORIGIN_BEHAVIOR } from '@angular/fire/compat/functions';
import { AngularFireFunctionsModule, ORIGIN } from '@angular/fire/compat/functions';

@NgModule({
imports: [
Expand All @@ -159,10 +163,11 @@ import { AngularFireFunctionsModule, ORIGIN, NEW_ORIGIN_BEHAVIOR } from '@angula
],
...
providers: [
{ provide: NEW_ORIGIN_BEHAVIOR, useValue: true },
{ provide: ORIGIN, useValue: 'https://project-name.web.app' }
]
})
export class AppModule {}

```

Note: `REGION` and `ORIGIN` cannot be provided at the same time.
3 changes: 2 additions & 1 deletion docs/data-connect.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ As a prerequisite, ensure that `AngularFire` has been added to your project as d
Provide a Data Connect instance in the application's `app.config.ts`. `getDataConnect` takes a connector config that identifies your service, connector, and location; this is generated for you when you set up Data Connect and is also exported from your generated SDK:

```ts
import { ApplicationConfig } from '@angular/core';
import { provideFirebaseApp, initializeApp } from '@angular/fire/app';
import { provideDataConnect, getDataConnect } from '@angular/fire/data-connect';

Expand All @@ -30,7 +31,7 @@ export const appConfig: ApplicationConfig = {
provideDataConnect(() => getDataConnect(connectorConfig)),
...
],
...,
...
}
```

Expand Down
42 changes: 21 additions & 21 deletions docs/firestore.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,16 @@ import { execute, field, greaterThan } from '@angular/fire/firestore/lite/pipeli
class BooksComponent {
private firestore = inject(Firestore);

loadBooks() {
loadBooksChained() {
// Method Chaining
const pipeline = this.firestore.pipeline()
.collection('books')
.where(field('rating').greaterThan(4.5));

return execute(pipeline);
}

loadBooksFunctional() {
// Functional Approach
const pipeline = this.firestore.pipeline()
.collection('books')
Expand Down Expand Up @@ -106,6 +110,7 @@ In `user-profile.component.ts`:

```typescript
import { Firestore, FirestoreDataConverter, collection, collectionData } from '@angular/fire/firestore';
import { AsyncPipe } from '@angular/common';
import { Component, inject } from '@angular/core';
import { Observable } from 'rxjs';

Expand All @@ -126,9 +131,9 @@ export const userProfileConverter: FirestoreDataConverter<UserProfile> = {
},
};

@Component ({
@Component({
selector: 'app-user-profile',
standalone: true,
imports: [AsyncPipe],
...
})
export class UserProfileComponent {
Expand All @@ -145,15 +150,15 @@ export class UserProfileComponent {
}
```

`collectionData` returns an `observable` that can we can use to display the data in the template. In `user-profile.component.html`:
`collectionData` returns an `Observable` that we can use to display the data in the template. In `user-profile.component.html`:

```html
<section>
<h1>User Profiles</h1>
<ul>
<li *ngFor="let user of users$ | async">
{{user.username}}
</li>
@for (user of users$ | async; track user) {
<li>{{ user.username }}</li>
}
</ul>
</section>
```
Expand All @@ -177,35 +182,30 @@ To write to Cloud Firestore use the `addDoc` function. It will create a new docu


```typescript
import { Firestore, collection, collectionData, addDoc, CollectionReference, DocumentReference } from '@angular/fire/firestore';
import { Firestore, collection, addDoc, CollectionReference, DocumentReference } from '@angular/fire/firestore';
import { Component, inject } from '@angular/core';
import { Observable } from 'rxjs';
// Uses UserProfile and userProfileConverter from the example above

@Component ({
@Component({
selector: 'app-user-profile',
standalone: true,
...
})
export class UserProfileComponent {
private firestore: Firestore = inject(Firestore); // inject Cloud Firestore
users$: Observable<UserProfile[]>;
usersCollection: CollectionReference;

constructor() {...}
private usersCollection: CollectionReference<UserProfile> =
collection(this.firestore, 'users').withConverter(userProfileConverter);
...

addUserProfile(username: string) {
if (!username) return;

addDoc(this.usersCollection, <UserProfile> { username }).then((documentReference: DocumentReference) => {
addDoc(this.usersCollection, { username }).then((documentReference: DocumentReference<UserProfile>) => {
// the documentReference provides access to the newly created document
});
}
}
export interface UserProfile {
username: string;
}
```
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.
In the `addUserProfile` method we use a reference to the `this.usersCollection` and provide `UserProfile` data to 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.

## Learn More
More information on API methods and other functions can be found on the [Firebase Official Docs](https://firebase.google.com/docs/reference/js/firestore_)
More information on API methods and other functions can be found on the [Firebase Official Docs](https://firebase.google.com/docs/reference/js/firestore)
30 changes: 29 additions & 1 deletion docs/performance.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const appConfig: ApplicationConfig = {
Next inject `Performance` into your component:

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

@Component({ ... })
Expand All @@ -44,10 +44,38 @@ export class PerformanceComponent {
}
```

`Performance` is `null` during server rendering, although its type says `Performance`, so check it before use.

## Firebase API

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

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

[Getting Started](https://firebase.google.com/docs/perf-mon/get-started-web) | [API Reference](https://firebase.google.com/docs/reference/js/performance)

## RxJS operators

`@angular/fire/performance` also exports RxJS operators (from `rxfire/performance`, wrapped for Angular) that create User Timing API traces picked up by Firebase Performance Monitoring (once `Performance` has been injected) and browser DevTools:

```ts
import { Component, inject } from '@angular/core';
import { Firestore, collection, collectionData } from '@angular/fire/firestore';
import { Performance, traceUntilFirst } from '@angular/fire/performance';

@Component({ ... })
export class ItemsComponent {
private firestore = inject(Firestore);
private performance = inject(Performance);
items$ = collectionData(collection(this.firestore, 'items')).pipe(
traceUntilFirst('items'),
);
}
```

| Operator | Behavior |
| --- | --- |
| `traceUntilFirst(name: string)` | Traces from subscription until the first emission. |
| `traceUntilComplete(name: string)` | Traces from subscription until the observable completes. |
| `traceUntil(name: string, test: (value: T) => boolean, options?: { orComplete?: boolean })` | Traces from subscription until the first emission where `test(value)` returns `true` (or until completion if `options.orComplete` is `true`). |
| `traceWhile(name: string, test: (value: T) => boolean, options?: { orComplete?: boolean })` | Starts tracing when `test(value)` returns `true` and stops when an emission returns `false` (or on completion if `options.orComplete` is `true`). |