// signup.component.ts import { Component } from '@angular/core'; import { FormsModule } from '@angular/forms'; @Component({ selector: 'app-signup', standalone: true, imports: [FormsModule], template: `
@if (name.invalid && name.touched) { Name is required. }
@if (email.invalid && email.touched) { A valid email is required. }
`, }) export class SignupComponent { model = { name: '', email: '' }; onSubmit() { console.log(this.model); } } /* Notes: - Each input gets its own #ref="ngModel" (e.g. #email="ngModel") capturing that single control's state. - The message only shows when the control is both invalid AND touched — so an untouched empty form doesn't show errors immediately, only after the user has focused and left the field. */