Loading

Quipoin Menu

Learn • Practice • Grow

angular / Angular Forms
interview

Q1. What are the two approaches to building forms in Angular?
Angular provides two approaches: Template-driven forms and Reactive forms. Template-driven forms are simpler, use directives like ngModel, and put logic in the template. Reactive forms are more robust, use model-driven approach with FormGroup and FormControl, and are easier to test and validate.

Q2. What is the difference between template-driven and reactive forms?
Template-driven: asynchronous, less code in component, relies on directives, validation in template, harder to unit test. Reactive: synchronous, more control, validation in component, easily testable, better for complex forms. Choose reactive for complex, dynamic forms; template-driven for simple ones.

Q3. What modules are needed for forms?
For template-driven forms, import FormsModule. For reactive forms, import ReactiveFormsModule. Both are from @angular/forms. They can be used together in the same module, but typically you choose one approach.

Q4. What is FormControl, FormGroup, and FormArray?
FormControl tracks the value and validation of an individual form control. FormGroup tracks a group of FormControl instances. FormArray tracks an array of controls. They are building blocks of reactive forms and provide status, errors, and value changes.

Q5. How do you access form controls in the template?
For reactive forms, use [formGroup]="myForm" and formControlName="fieldName". For template-driven, use [(ngModel)]="property" and name attribute. Both approaches expose the control''s state for validation feedback.