You signed in with another tab or window.Reload to refresh your session.You signed out in another tab or window.Reload to refresh your session.You switched accounts on another tab or window.Reload to refresh your session.Dismiss alert
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
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.
```ts
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import { environment } from '../environments/environment';
// AngularFire 7
// import { initializeApp, provideFirebaseApp } from '@angular/fire/app';
// import { provideFirestore, getFirestore } from '@angular/fire/firestore';
This view has a button for user input and displays the data returned from the cloud function.
### Injecting the AngularFireFunctions service
Once the `AngularFireFunctionsModule` is registered you can inject the `AngularFireFunctions` service.
Expand All
@@ -50,25 +83,79 @@ 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. |
`data$` handles the data returned from the cloud function and displays the data in the view.
The component handles two functions, one that executes on page load and another that executes on user input.
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.
### Make your callable cloud functions
```js
// The Cloud Functions for Firebase SDK to create Cloud Functions and set up triggers.
The first function executes when the page loads. The second function executes from user input.
Both functions use `https.onCall((data, context) => {})`, which makes a function callable from Angular.
`data` is the data sent from Angular. `context` is metadata about the function executing. The returned data (`22`, `57`) goes back to Angular and is displayed in the view. This data is an Observable.
## Configuration via Dependency Injection
### Functions Region
Expand Down
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.