Challenge - 5 Problems
FormsModule Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What happens when FormsModule is not imported?
Consider an Angular component template using
[(ngModel)] for two-way binding on an input field. What will happen if the FormsModule is not imported in the module?Angular
<input [(ngModel)]="username" />Attempts:
2 left
💡 Hint
Think about what Angular needs to recognize
ngModel in templates.✗ Incorrect
Without importing FormsModule, Angular does not know about the ngModel directive. This causes a template parse error.
📝 Syntax
intermediate2:00remaining
Correct way to import FormsModule in Angular standalone component
You have a standalone Angular component that uses
[(ngModel)]. Which is the correct way to import FormsModule for this component?Angular
import { Component } from '@angular/core'; import { FormsModule } from '@angular/forms'; @Component({ selector: 'app-input', standalone: true, imports: [/* What goes here? */], template: `<input [(ngModel)]="name" />` }) export class InputComponent { name = ''; }
Attempts:
2 left
💡 Hint
Which module provides the
ngModel directive?✗ Incorrect
For standalone components, you must explicitly import FormsModule in the imports array to use ngModel.
❓ state_output
advanced2:00remaining
What is the value of the model after input change?
Given this Angular component using FormsModule, what will be the value of
userName after the user types 'Angular' in the input field?Angular
import { Component } from '@angular/core'; import { FormsModule } from '@angular/forms'; @Component({ selector: 'app-user', template: `<input [(ngModel)]="userName" />`, standalone: true, imports: [FormsModule] }) export class UserComponent { userName = ''; }
Attempts:
2 left
💡 Hint
Two-way binding updates the property as the input changes.
✗ Incorrect
The [(ngModel)] directive binds the input value to the userName property. Typing 'Angular' updates userName to 'Angular'.
🔧 Debug
advanced2:00remaining
Why does this form control not update the model?
This Angular component uses
FormsModule and ngModel, but the model property does not update when typing. What is the likely cause?Angular
import { Component } from '@angular/core'; import { FormsModule } from '@angular/forms'; @Component({ selector: 'app-debug', template: `<input [ngModel]="email" />`, standalone: true, imports: [FormsModule] }) export class DebugComponent { email = ''; }
Attempts:
2 left
💡 Hint
Check the difference between one-way and two-way binding syntax.
✗ Incorrect
Using [ngModel] binds the input value one-way only. To update the model on input changes, use [(ngModel)] for two-way binding.
🧠 Conceptual
expert3:00remaining
Why is FormsModule needed for template-driven forms?
Which statement best explains why Angular requires importing
FormsModule to use template-driven forms with ngModel?Attempts:
2 left
💡 Hint
Think about what Angular needs to recognize and process
ngModel in templates.✗ Incorrect
FormsModule contains the ngModel directive and the services Angular uses to support template-driven forms, including two-way binding and validation.