Bird
0
0

You have this Angular module code:

medium📝 Debug Q6 of 15
Angular - Template-Driven Forms
You have this Angular module code:
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppComponent } from './app.component';

@NgModule({
  declarations: [AppComponent],
  imports: [BrowserModule],
  bootstrap: [AppComponent]
})
export class AppModule {}

You try to use [(ngModel)] in AppComponent template but get an error. What is the fix?
AAdd <code>FormsModule</code> to the imports array of <code>AppModule</code>
BAdd <code>ReactiveFormsModule</code> to the declarations array
CAdd <code>FormsModule</code> to the declarations array
DRemove <code>BrowserModule</code> from imports
Step-by-Step Solution
Solution:
  1. Step 1: Identify missing FormsModule

    ngModel directive requires FormsModule to be imported in the module where the component is declared.
  2. Step 2: Correct import placement

    FormsModule must be added to the imports array, not declarations or removed modules.
  3. Final Answer:

    Add FormsModule to the imports array of AppModule -> Option A
  4. Quick Check:

    ngModel error fix = import FormsModule [OK]
Quick Trick: Always import FormsModule in module imports for ngModel [OK]
Common Mistakes:
MISTAKES
  • Adding FormsModule to declarations instead of imports
  • Confusing ReactiveFormsModule with FormsModule
  • Removing BrowserModule unnecessarily

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes