How to use reactive forms in Angular

Building robust, type-safe forms with programmatic control is essential for enterprise Angular applications that require complex validation and dynamic form behavior. As the creator of CoreUI, I’ve implemented reactive forms extensively in our admin templates for their superior validation capabilities and testability. The most effective approach is using Angular’s FormBuilder service with FormGroup and FormControl to create strongly-typed form structures. This method provides programmatic control over form state, validation, and values while maintaining clean separation between template and component logic.

Use FormBuilder to create reactive forms with FormGroup and FormControl for programmatic form management.

import { Component } from '@angular/core'
import { FormBuilder, FormGroup, Validators } from '@angular/forms'

@Component({
  selector: 'app-user-form',
  template: `
    <form [formGroup]="userForm" (ngSubmit)="onSubmit()">
      <input formControlName="name" placeholder="Name">
      <input formControlName="email" placeholder="Email">
      <button type="submit" [disabled]="!userForm.valid">Submit</button>
    </form>
  `
})
export class UserFormComponent {
  userForm: FormGroup

  constructor(private fb: FormBuilder) {
    this.userForm = this.fb.group({
      name: ['', Validators.required],
      email: ['', [Validators.required, Validators.email]]
    })
  }

  onSubmit() {
    if (this.userForm.valid) {
      console.log(this.userForm.value)
    }
  }
}

Reactive forms use FormBuilder to create a FormGroup containing FormControl instances that represent form inputs. The formControlName directive connects template inputs to form controls, while [formGroup] binds the entire form. This approach provides immutable form state, programmatic validation, and reactive updates through observables. You can access form values, validation status, and individual control states programmatically, making forms predictable and easy to test.

Best Practice Note:

This is the preferred form approach we use in CoreUI Angular components for enterprise applications requiring complex validation and dynamic behavior. Import ReactiveFormsModule in your module and consider using typed forms with Angular 14+ for enhanced type safety and better developer experience.


Speed up your responsive apps and websites with fully-featured, ready-to-use open-source admin panel templates—free to use and built for efficiency.


About the Author

Subscribe to our newsletter
Get early information about new products, product updates and blog posts.
How to set focus on an input field after rendering in React
How to set focus on an input field after rendering in React

Passing props to child components in React function components
Passing props to child components in React function components

How to loop inside React JSX
How to loop inside React JSX

How to validate an email address in JavaScript
How to validate an email address in JavaScript