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 pageshowhide
explore
- Template-Driven Model6 questions
- Reactive Control Tree5 questions
- Typed Controls4 questions
- Validator Functions4 questions
- Dynamic Structures4 questions
- Custom Value Accessors4 questions
- Signal-Based Model5 questions
questions
page 2 of 2An 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 sNgModel 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.
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 sUntyped 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.
showing 31–32 of 32