• Overview
@angular/forms/signals

A reusable schema that defines behavior and rules for a form.

API

    
      type Schema<TModel> = {  [ɵɵTYPE]: SchemaFn<TModel, PathKind.Root>;}
    
    

Description

A reusable schema that defines behavior and rules for a form.

A Schema encapsulates form logic such as validation rules, disabled states, readonly states, and other field-level behaviors.

Unlike raw SchemaFn, a Schema is created using the schema function and is cached per-form, even when applied to multiple fields.

Creating a reusable schema

interface Address {  street: string;  city: string;}// Create a reusable schema for address fieldsconst addressSchema = schema<Address>((p) => {  required(p.street);  required(p.city);});// Apply the schema to multiple formsconst shippingForm = form(shippingModel, addressSchema, {injector});const billingForm = form(billingModel, addressSchema, {injector});

Passing a schema to a form

A schema can also be passed as a second argument to the form function.

readonly userForm = form(addressModel, addressSchema);
Jump to details