/
githubmirror
/
angular
Обзор
Документация
Войти
/
githubmirror
/
angular
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
packages/forms/signals/src/directive/form_root.ts
57 строк
1 KB
SkyZeroZx
docs: add `@see` references to Signal Forms
06 июл 2026, 23:35
06 июл 2026, 23:35
bbbcf8f
Код
Авторство
О чём код?
/** * @license * Copyright Google LLC All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.dev/license */ import {Directive, input, untracked} from '@angular/core'; import {submit} from '../api/structure'; import {FieldState, FieldTree} from '../api/types'; import {FieldNode} from '../field/node'; /** * A directive that binds a `FieldTree` to a `<form>` element. * * It automatically: * 1. Sets `novalidate` on the form element to disable browser validation. * 2. Listens for the `submit` event, prevents the default behavior, and calls `submit()` on the * `FieldTree` if it defines its own submission options. * * @usageNotes * * ```html * <form [formRoot]="myFieldTree"> * ... * </form> * ``` * * @see [Setting up form submission with FormRoot](guide/forms/signals/form-submission#setting-up-form-submission-with-formroot) * * @publicApi 22.0 */ @Directive({ selector: 'form[formRoot]', host: { 'novalidate': '', '(submit)': 'onSubmit($event)', }, }) export class FormRoot<T> { readonly fieldTree = input.required<FieldTree<T>>({alias: 'formRoot'}); protected onSubmit(event: Event): void { event.preventDefault(); untracked(() => { const fieldTree = this.fieldTree(); const node = fieldTree() as FieldState<unknown> as FieldNode; if (node.structure.fieldManager.submitOptions) { submit(fieldTree); } }); } }