Bird
0
0

In an Angular standalone component, you wrote:

medium📝 Debug Q7 of 15
Angular - Template-Driven Forms
In an Angular standalone component, you wrote:
@Component({
  selector: 'app-example',
  template: ``,
  standalone: true
})
export class ExampleComponent {
  name = '';
}

The input does not bind correctly. What is missing?
AThe component must declare name as a FormControl
BThe component must add name to providers
CThe component must import ReactiveFormsModule
DThe component must import FormsModule in its imports array
Step-by-Step Solution
Solution:
  1. Step 1: Recognize standalone component needs FormsModule

    Standalone components must explicitly import FormsModule to use ngModel.
  2. Step 2: Understand missing imports cause binding failure

    Without FormsModule in imports, ngModel directive is unknown and binding fails.
  3. Final Answer:

    The component must import FormsModule in its imports array -> Option D
  4. Quick Check:

    Standalone ngModel needs FormsModule import [OK]
Quick Trick: Standalone components require FormsModule import for ngModel [OK]
Common Mistakes:
MISTAKES
  • Confusing ReactiveFormsModule with FormsModule
  • Trying to declare name as FormControl without ReactiveFormsModule
  • Adding name to providers incorrectly

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes