Quick Start
This guide will walk you through creating a complete, functional user registration form using Mat Dynamic Form. You’ll learn the basics of form structure, validation, and retrieving form values.Before starting, make sure you’ve completed the installation steps.
What We’ll Build
We’re going to create a user registration form with:- Name and email inputs with validation
- Password field with confirmation
- Birth date picker
- Country dropdown selection
- Terms and conditions checkbox
- Submit and reset buttons
Step-by-Step Guide
Import required classes
Open
user-registration.component.ts and import the necessary classes from Mat Dynamic Form:user-registration.component.ts
Define the form structure
Create the form structure in your component class:
user-registration.component.ts
Key concepts used here:
FormStructure- The main container for your formnodes- Array of form fieldsvalidateActions- Action buttons (submit, reset, etc.).apply()- Method to configure field propertiesvalidator- Angular validators for field validation
Add the template
Update That’s it! The
user-registration.component.html with the form component:user-registration.component.html
mat-dynamic-form component renders the entire form based on your configuration.Add styling (optional)
Add some basic styling in
user-registration.component.scss:user-registration.component.scss
Success! You’ve created your first Mat Dynamic Form. The form includes validation, Material Design styling, and is fully reactive.
Understanding the Code
Form Structure Properties
title- Displays at the top of the formappearance- Material form field style:'fill','outline', or'standard'nodeGrid- Number of columns (1-4) for responsive grid layout
Creating Form Fields
Each field is created using its corresponding class:The apply() Method
The.apply() method is a convenient way to set multiple properties on a node:
Action Buttons
Buttons are defined in thevalidateActions array:
Getting Form Values
There are several ways to retrieve form values:Get All Values
Get Raw Values (Including Disabled Fields)
Get Individual Field Values
Check Form Validity
Setting Form Values
You can programmatically set form values:Adding Dynamic Behavior
Let’s enhance the form to show additional fields based on user selection:Complete Example
Here’s the complete working example:What’s Next?
Now that you’ve built your first dynamic form, explore more advanced features:Core Concepts
Deep dive into FormStructure, Nodes, and the apply() method
Form Fields
Learn about all available form field types and their options
Validation
Master form validation with built-in and custom validators
Actions & Events
Handle user interactions and create dynamic forms
Pro Tip: Check out the GitHub repository for more examples and the complete source code.
