• Overview
@angular/forms/signals

applyEach

function
stablesince v22.0

Applies a schema to each item of an array.

API

function applyEach<TValue extends ReadonlyArray<any>>(
  path: SchemaPath<TValue>,
  schema: NoInfer<SchemaOrSchemaFn<TValue[number], Item>>,
): void;
function applyEach<TValue extends Object>(
  path: SchemaPath<TValue>,
  schema: NoInfer<SchemaOrSchemaFn<ItemType<TValue>, Child>>,
): void;
function applyEach<TValue>(path: SchemaPath<TValue>, schema: NoInfer<SchemaOrSchemaFn<TValue[number], Item>>): void;

Applies a schema to each item of an array.

@parampathSchemaPath<TValue>

The target path for an array field whose items the schema will be applied to.

@paramschemaNoInfer<SchemaOrSchemaFn<TValue[number], Item>>

A schema for an element of the array, or function that binds logic to an element of the array.

@returnsvoid
Usage notes
const nameSchema = schema<{first: string, last: string}>((name) => {
  required(name.first);
  required(name.last);
});
const namesForm = form(signal([{first: '', last: ''}]), (names) => {
  applyEach(names, nameSchema);
});
function applyEach<TValue>(path: SchemaPath<TValue>, schema: NoInfer<SchemaOrSchemaFn<ItemType<TValue>, Child>>): void;
@parampathSchemaPath<TValue>
@paramschemaNoInfer<SchemaOrSchemaFn<ItemType<TValue>, Child>>
@returnsvoid

Usage Notes

const nameSchema = schema<{first: string, last: string}>((name) => {
  required(name.first);
  required(name.last);
});
const namesForm = form(signal([{first: '', last: ''}]), (names) => {
  applyEach(names, nameSchema);
});
Jump to details