October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk5 min

How to Build Dynamic Forms with JSON in Angular

Angular Signal Forms can derive a dynamic form’s model, validation schema, and rendered fields from one runtime configuration. Here’s how the pattern works and how it differs from reactive forms and FormArray.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

For forms whose fields genuinely change at runtime, Angular’s Signal Forms can derive the model, validation schema, and rendered controls from one JSON configuration. This keeps those pieces aligned as the configured form changes. For a form whose structure is known when you build the application, a conventional static form is usually a better fit and offers stronger compile-time checking.

When should you use a JSON-driven form?

Use runtime configuration when the application cannot know a form’s structure at compile time—for example, when a backend, admin panel, tenant setting, or content-management system determines which fields and rules to show. This can let a form change without a frontend redeployment, provided the application is designed to receive and safely handle those changes.

As an Amazon Associate I earn from qualifying purchases.

If the fields are fixed in the application, prefer a static form. Angular notes that this gives stronger TypeScript checking and straightforward testing and tooling. JSON configuration adds flexibility, but it also moves some guarantees from compile time into the code that validates and interprets that configuration.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The current Angular guide describes the pattern this way: “This guide shows how to build forms whose model, schema, validation, and rendering are all derived from a single runtime configuration.” The guide demonstrates this using Signal Forms: Dynamic Forms with JSON.

How the configuration drives the form

Represent each field as a typed object with a discriminator such as kind, plus a name, label, and any kind-specific validation settings. A discriminated union can describe the allowed field types and the properties each type supports. For example, a text field can carry a required setting, while a numeric field can carry minimum and maximum values.

From that field list, create three connected parts:

  • Model: a property for each configured field, initialized to a value compatible with its kind.
  • Schema: validators derived from the same field definitions.
  • Rendering: the appropriate input for each field kind, with its label and validation feedback.

Using the same configuration for all three avoids mismatches such as rendering a numeric input while initializing a string value, or displaying a field without its configured rules. In Angular’s example, text values start as empty strings and numeric values as null. Starting a required numeric field at zero would make it look filled and might also fail a positive minimum before the user enters anything.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The example builds its model and schema when the component is constructed, assuming the configuration is already available synchronously. It does not demonstrate the full lifecycle for fetching configuration asynchronously or changing it after form creation; those cases require application code to coordinate configuration arrival or updates with form construction.

Render configured fields by kind

Angular’s example loops over the configuration with @for and uses a @switch on each field’s kind to choose an input. Conceptually, the template follows this pattern:

@for (field of fields; track field.name) {
  @switch (field.kind) {
    @case ('text') {
      <input [field]="textField(field.name)" [id]="field.name" />
    }
    @case ('number') {
      <input type="number" [field]="numberField(field.name)" [id]="field.name" />
    }
  }
}

The important typing detail is that narrowing field.kind in a template branch does not automatically narrow a separate dynamic lookup such as dynamicForm[field.name]. The official example uses typed accessors and casts at the binding point. The cast bridges that dynamic lookup boundary; the matching kind branch is what makes the runtime type appropriate. Keep field-name checks and validation of incoming configuration in application code rather than treating the cast as validation.

Add validation from configuration

Build the schema by walking the same field definitions used to create the model. The documented example handles required text fields and numeric minimum and maximum rules. This keeps validation attached to the field’s configuration instead of maintaining a separate, easily divergent list of rules.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Signal Forms schemas establish the logic tree during form creation, while rule functions express reactive behavior at runtime. Conditions and dependencies can therefore be composed into the schema rather than being treated as unrelated template checks. See Angular’s schemas and schema composability guide.

Handle dependent rules, visibility, and repeated fields

Conditional validation

A field configuration can include a when condition that names another field and the value that activates a rule. The guide’s applyWhen() example applies configured validation while that condition holds; when it becomes false, the rule deactivates and the field’s validation state clears.

Conditional visibility

When the requirement is to hide a field rather than merely change whether it is valid, Angular’s example uses hidden() on the field path. Visibility and validation are distinct concerns: decide explicitly whether a hidden field should still participate in validation or submission in your application.

Arrays and variable-length sections

For repeated fields, the example supplies array defaults, applies per-item validation with applyEach(), and adds or removes items in the model. Each new item receives fresh validation state; removing an item removes its associated state as well. This is useful for configured sections where users can add multiple entries, but the configuration and rendering still need to describe what one item contains.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Signal Forms versus reactive forms and FormArray

Angular’s JSON-driven guide is specifically about Signal Forms, not the classic reactive-forms API. Both can support dynamic data entry, but the structure is represented differently.

Approach Where structure lives Repeated controls Typing and testing considerations
Signal Forms driven by JSON Runtime field configuration drives the model, schema, and rendering together. Configuration can describe variable-length arrays; the guide demonstrates per-item rules with applyEach(). Useful when structure is runtime-defined. Dynamic template indexing may need typed accessors and casts; incoming configuration needs application-level validation.
Reactive forms Controls are constructed explicitly as a model-driven form. FormArray manages any number of unnamed controls, with values and validation status derived from its controls; controls can be inserted or removed at runtime. Appropriate when explicit control construction is the desired model. Angular describes reactive forms as providing synchronous access to form data.
Static form Fields and structure are known in application code at build time. Use a fixed structure when the number and shape of fields do not vary. Angular recommends this for known structure because it offers stronger TypeScript checking and straightforward testing and tooling.

For reactive forms, the relevant module infrastructure and directives are provided by ReactiveFormsModule; see Angular’s API reference and reactive forms guide. Angular’s forms overview distinguishes reactive and template-driven forms and points readers to the dedicated Signal Forms guide. A separate Angular v18 dynamic forms tutorial shows a metadata-driven reactive-forms approach; it is version-specific background, not the current JSON-driven Signal Forms example.

Implementation checks before using server configuration

  • Use a typed field definition with a clear discriminator and only the settings each field kind supports.
  • Derive defaults and validators from that same definition so the model and schema agree.
  • Validate field names, kinds, and rule values before using incoming JSON to build a form.
  • Choose initial values intentionally, especially for required numeric fields.
  • Decide how asynchronous configuration loading and later configuration changes will affect form creation and existing user input.
  • Use reactive conditions for dependent rules, and distinguish conditional visibility from validation behavior.
  • Use a fixed, statically typed form when runtime variation does not justify the extra configuration layer.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Outdated Drivers Are Slowing You DownFree scan - exact matches

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.