Bird
0
0

Given this Angular module setup:

medium📝 Predict Output Q4 of 15
Angular - Template-Driven Forms
Given this Angular module setup:
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule } from '@angular/forms';
import { AppComponent } from './app.component';

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

What will happen if you remove FormsModule from the imports array but keep using [(ngModel)] in templates?
AAngular will throw a template parse error for unknown ngModel directive
BThe application will work normally without errors
CngModel will work but without two-way binding
DThe app will fail to compile due to missing BrowserModule
Step-by-Step Solution
Solution:
  1. Step 1: Understand ngModel dependency

    ngModel directive is provided by FormsModule, so it requires FormsModule to be imported.
  2. Step 2: Effect of removing FormsModule

    Without FormsModule, Angular does not recognize ngModel and throws a template parse error.
  3. Final Answer:

    Angular will throw a template parse error for unknown ngModel directive -> Option A
  4. Quick Check:

    ngModel needs FormsModule = error if missing [OK]
Quick Trick: ngModel requires FormsModule import to avoid template errors [OK]
Common Mistakes:
MISTAKES
  • Assuming ngModel works without FormsModule
  • Confusing BrowserModule with FormsModule
  • Expecting silent failure instead of error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes