Bird
0
0

Given this component template and setup, what will be the initial value shown in the input box?

medium📝 state output Q13 of 15
Angular - Template-Driven Forms
Given this component template and setup, what will be the initial value shown in the input box?
<input [(ngModel)]="username" />

Component code:
@Component({
  standalone: true,
  imports: [FormsModule]
})
export class MyComponent {
  username = 'Alice';
}
AEmpty input box
BAlice
Cundefined
DError: ngModel not recognized
Step-by-Step Solution
Solution:
  1. Step 1: Check FormsModule import and ngModel usage

    The component imports FormsModule and uses [(ngModel)] binding on username.
  2. Step 2: Check initial value of username

    The username property is initialized to 'Alice', so the input box will show 'Alice' initially.
  3. Final Answer:

    Alice -> Option B
  4. Quick Check:

    ngModel binds username = 'Alice' [OK]
Quick Trick: Initial value = component property value [OK]
Common Mistakes:
MISTAKES
  • Forgetting to import FormsModule causes error
  • Assuming input is empty by default
  • Confusing one-way and two-way binding

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes