Angular·Practice drills 10

Drill 25: List the steps — Reactive forms

List the steps the code follows in order.

Intermediate 5 min read Lesson 257 of 300 Challenge included
What you will be able to do
  • List the steps the code follows in order.

Practice task

List the steps the code follows in order.

signup.component.tsTYPESCRIPT
import { Component, inject } from '@angular/core'
import { NonNullableFormBuilder, ReactiveFormsModule, Validators } from '@angular/forms'

@Component({
  selector: 'app-signup',
  standalone: true,
  imports: [ReactiveFormsModule],
  template: `
    <form [formGroup]="form" (ngSubmit)="submit()">
      <label>Email <input formControlName="email" type="email"></label>
      @if (form.controls.email.touched && form.controls.email.invalid) {
        <p>Enter a valid email.</p>
      }
      <button [disabled]="form.invalid">Subscribe</button>
    </form>
  `,
})
export class SignupComponent {
  private fb = inject(NonNullableFormBuilder)
  form = this.fb.group({ email: ['', [Validators.required, Validators.email]] })
  submit() { if (this.form.valid) console.log(this.form.getRawValue()) }
}
Your turn

Write your answer

Easy

List the steps the code follows in order.

TEXT · starter
Your answer…
Study tools

Make it yours.

Keep a private note for this lesson, then turn the key ideas into flashcards you can revisit.

Sign in to save notes and flashcards.Both are private to your account and stay with your progress.
Sign in
Finished reading?

Lock in what you just learned.

Mark this lesson complete to save your place and move one step closer to the certificate.

Lesson 257 of 300 · 0% of course