Firebase Cloud Functions integration for calling server-side functions directly from Angular applications with automatic serialization and error handling.
export function provideFunctions(fn: () => Functions): EnvironmentProviders;
export function getFunctions(app?: FirebaseApp, regionOrCustomDomain?: string): Functions;export class Functions extends Functions {}
export class FunctionsInstances extends Array<Functions> {}
export const functionInstance$: Observable<Functions>;/**
* Create callable function reference
* @param functions - Functions instance
* @param name - Function name
* @param options - Optional call options
* @returns Callable function
*/
export function httpsCallable<T = any, R = any>(
functions: Functions,
name: string,
options?: HttpsCallableOptions
): HttpsCallable<T, R>;
/**
* Connect to Functions emulator
* @param functions - Functions instance
* @param host - Emulator host
* @param port - Emulator port
*/
export function connectFunctionsEmulator(
functions: Functions,
host: string,
port: number
): void;
interface HttpsCallable<T = any, R = any> {
(data?: T): Promise<HttpsCallableResult<R>>;
}
interface HttpsCallableResult<T = any> {
readonly data: T;
}import { Component, inject } from '@angular/core';
import { Functions, httpsCallable } from '@angular/fire/functions';
@Component({
selector: 'app-functions',
template: `...`,
})
export class FunctionsComponent {
private functions = inject(Functions);
async processPayment(paymentData: any) {
const processPaymentFn = httpsCallable(this.functions, 'processPayment');
try {
const result = await processPaymentFn(paymentData);
console.log('Payment processed:', result.data);
return result.data;
} catch (error) {
console.error('Payment error:', error);
throw error;
}
}
async sendNotification(message: string, userId: string) {
const sendNotificationFn = httpsCallable<{message: string, userId: string}, {success: boolean}>(
this.functions,
'sendNotification'
);
const result = await sendNotificationFn({ message, userId });
return result.data.success;
}
}