# Content temporarily unavailable
As a form grows, keeping every field in one component can make the code harder
to navigate and maintain. You can move related fields into smaller components
while keeping one form instance, but each new component boundary needs a type
for the form or field it receives.

## Split a large form into sections

First define the form's reusable options with `formOptions`. In this example,
the same module also exports a named form type derived from those options. The
parent can add page-specific options, such as `onSubmit`, when it creates the
form, while extracted sections can import the same form type.

Angular's `AngularFormType` derives the form input from the shared options. The
result keeps the field names and values available to `TanStackField` in the
extracted component.

<!-- ::start:tabs variant="files" -->

```ts file="shared-form.ts"
import { formOptions } from '@tanstack/angular-form'
import type { AngularFormType } from '@tanstack/angular-form'

export const profileFormOptions = formOptions({
  defaultValues: {
    name: '',
    address: {
      street: '',
      city: '',
    },
  },
})

export type ProfileForm = AngularFormType<typeof profileFormOptions>
```

```ts file="address-fields.component.ts"
import { ChangeDetectionStrategy, Component, input } from '@angular/core'
import { TanStackField } from '@tanstack/angular-form'
import type { ProfileForm } from './shared-form'

@Component({
  selector: 'app-address-fields',
  standalone: true,
  changeDetection: ChangeDetectionStrategy.OnPush,
  imports: [TanStackField],
  template: `
    <ng-container
      [tanstackField]="form()"
      name="address.street"
      #street="field"
    >
      <input
        aria-label="Street"
        [value]="street.api.value"
        (input)="street.api.handleChange($any($event).target.value)"
      />
    </ng-container>
    <ng-container [tanstackField]="form()" name="address.city" #city="field">
      <input
        aria-label="City"
        [value]="city.api.value"
        (input)="city.api.handleChange($any($event).target.value)"
      />
    </ng-container>
  `,
})
export class AddressFieldsComponent {
  form = input.required<ProfileForm>()
}
```

```ts file="profile-form.component.ts"
import { ChangeDetectionStrategy, Component } from '@angular/core'
import { injectForm } from '@tanstack/angular-form'
import { AddressFieldsComponent } from './address-fields.component'
import { profileFormOptions } from './shared-form'

@Component({
  selector: 'app-profile-form',
  standalone: true,
  changeDetection: ChangeDetectionStrategy.OnPush,
  imports: [AddressFieldsComponent],
  template: `<app-address-fields [form]="form" />`,
})
export class ProfileFormComponent {
  form = injectForm({
    ...profileFormOptions,
    onSubmit: ({ value }) => console.log(value),
  })
}
```

<!-- ::end:tabs -->

## Extract a field component by value type

After splitting the form into sections, you may still have repeated controls
for values such as strings, numbers, or dates. These controls don't need to
know the form's complete data shape or the path of a particular field. They
only need the type of the value they read and update.

`FieldWithValue<T>` describes a field by the value type a reusable component
handles. This preserves type checking when the component reads or updates the
value without tying it to a particular field path or form shape.

Angular field components can declare their value type through
`injectField<string>()`. The `tanstack-app-field` directive provides the field
to that component, so it doesn't need a form input of its own.

<!-- ::start:tabs variant="files" -->

```ts file="text-field.component.ts"
import { ChangeDetectionStrategy, Component, input } from '@angular/core'
import { injectField } from '@tanstack/angular-form'

@Component({
  selector: 'app-text-field',
  standalone: true,
  changeDetection: ChangeDetectionStrategy.OnPush,
  template: `
    <label>
      <span>{{ label() }}</span>
      <input
        [name]="field.api.name"
        [value]="field.api.value"
        (blur)="field.api.handleBlur()"
        (input)="field.api.handleChange($any($event).target.value)"
      />
    </label>
  `,
})
export class TextFieldComponent {
  label = input.required<string>()
  field = injectField<string>()
}
```

```ts file="name-field.component.ts"
import { ChangeDetectionStrategy, Component, input } from '@angular/core'
import { TanStackAppField, TanStackField } from '@tanstack/angular-form'
import { TextFieldComponent } from './text-field.component'
import type { ProfileForm } from './shared-form'

@Component({
  selector: 'app-name-field',
  standalone: true,
  changeDetection: ChangeDetectionStrategy.OnPush,
  imports: [TanStackAppField, TanStackField, TextFieldComponent],
  template: `
    <app-text-field
      tanstack-app-field
      [tanstackField]="form()"
      name="name"
      label="Name"
    />
  `,
})
export class NameFieldComponent {
  form = input.required<ProfileForm>()
}
```

<!-- ::end:tabs -->

## Accept any form or field

Some extracted controls behave the same regardless of the form's data. An
error display only needs field metadata, while a submit or reset button may
only need form state and methods. Giving these controls the concrete
`ProfileForm` type would couple them to details they don't use.

Use `AnyFieldApi` when a control doesn't depend on the field's value type. For
form-level controls, use the adapter's `Any*FormApi` type. These types
deliberately remove information about values and field paths, so use a concrete
type when a component reads either one.

For a field control that doesn't read the value, use `injectField<unknown>()`
to receive the field and react to its metadata. Angular provides
`AnyAngularFormApi` when a separate component only needs form methods.

<!-- ::start:tabs variant="files" -->

```ts file="field-errors.component.ts"
import { ChangeDetectionStrategy, Component } from '@angular/core'
import { injectField } from '@tanstack/angular-form'

@Component({
  selector: 'app-field-errors',
  standalone: true,
  changeDetection: ChangeDetectionStrategy.OnPush,
  template: `
    <small role="alert" aria-live="polite">
      @for (error of field.api.errors; track error) {
        {{ error.message }}
      }
    </small>
  `,
})
export class FieldErrorsComponent {
  field = injectField<unknown>()
}
```

```ts file="reset-button.component.ts"
import { ChangeDetectionStrategy, Component, input } from '@angular/core'
import type { AnyAngularFormApi } from '@tanstack/angular-form'

@Component({
  selector: 'app-reset-button',
  standalone: true,
  changeDetection: ChangeDetectionStrategy.OnPush,
  template: `<button type="button" (click)="form().reset()">Reset</button>`,
})
export class ResetButtonComponent {
  form = input.required<AnyAngularFormApi>()
}
```

<!-- ::end:tabs -->
