skip to content

Forms

The @angular/forms package offers three models: template-driven ngModel, reactive FormGroup trees and signal-based form(). Interviewers ask which to pick and how each one tracks state.

part ofAngularoverview, primer and where to startread it →
on this pageshow

explore

questions

page 2 of 2

An Angular template-driven sign-up form moves its address inputs into a child component, and they stop affecting the parent form's value and validity. Why, and how do you fix it?

level: seniorimportance: nice to knowfreq 28%

basics

~20 s

NgModel looks for its parent ControlContainer with @Host(), which stops at the child component's boundary, so the child's inputs run as standalone controls. Add viewProviders: [{provide: ControlContainer, useExisting: NgForm}] to the child, or make it a proper custom form control.

open as a page

An Angular app still declares its reactive forms with UntypedFormGroup and UntypedFormControl; how would you move it to typed forms safely?

level: seniorimportance: nice to knowfreq 26%

basics

~20 s

Untyped classes are aliases of the typed ones with any as the value type, so migrate form by form: drop the Untyped prefix, let inference or an interface type it, fix the compile errors, and treat adding nonNullable as a runtime change.

open as a page

showing 31–32 of 32