Q1. How do you create a template-driven form?
Import FormsModule, then in template use ngModel for two-way binding. Example:
The template reference variable #myForm gives access to the form.Q2. What is ngForm and ngModel?
ngForm is a directive that creates a top-level FormGroup for the form. It''s automatically applied to
Q3. How do you add validation in template-driven forms?
Add standard HTML5 validation attributes like required, minlength, pattern. Angular picks them up and adds validation. Example:
Invalid email
Expose the control with #email="ngModel" to access its state.Q4. How do you track the form state?
Template-driven forms expose properties like valid, invalid, pristine, dirty, touched, untouched via the ngForm reference. Example:
Q5. What are the limitations of template-driven forms?
They are harder to test because logic is in template, less flexible for dynamic forms, validation logic is scattered, and they rely on directives which can be less explicit. For complex forms, reactive forms are recommended.
