Challenge - 5 Problems
Angular Forms Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What is the initial state of an Angular form using
ngForm?Consider a simple Angular template-driven form using
ngForm. What is the initial value of the form's valid and pristine properties right after the form loads?Angular
<form #myForm="ngForm"> <input name="email" ngModel required /> </form>
Attempts:
2 left
💡 Hint
Think about required fields and whether the user has changed anything yet.
✗ Incorrect
The form is initially pristine because the user hasn't interacted with it yet. Since the required field is empty, the form is invalid at the start.
❓ state_output
intermediate2:00remaining
What is the form's
dirty state after user input?Given this Angular form, after the user types any character into the input field, what will be the value of
myForm.dirty?Angular
<form #myForm="ngForm"> <input name="username" ngModel /> </form>
Attempts:
2 left
💡 Hint
Dirty means the user has changed the form since it loaded.
✗ Incorrect
Once the user changes any input, the form's dirty property becomes true.
📝 Syntax
advanced2:00remaining
Which option correctly binds the
ngForm directive to a template reference variable?Select the correct syntax to create a template reference variable named
formRef that references the ngForm directive on a form element.Attempts:
2 left
💡 Hint
Angular is case sensitive for directive export names.
✗ Incorrect
The correct syntax uses #formRef="ngForm" with exact casing to reference the ngForm directive.
🔧 Debug
advanced2:00remaining
Why does this Angular form's
valid property always stay true even with an empty required input?Examine the code below. The input is marked as required, but the form's
valid property remains true even when the input is empty. What is the cause?Angular
<form #myForm="ngForm"> <input name="email" required /> </form>
Attempts:
2 left
💡 Hint
Angular needs
ngModel to track form control state.✗ Incorrect
Without ngModel, Angular does not register the input as a form control, so validation does not apply.
🧠 Conceptual
expert3:00remaining
How does Angular's
ngForm directive aggregate child controls' states?In Angular template-driven forms, how does the
ngForm directive determine the overall form's valid and dirty states?Attempts:
2 left
💡 Hint
Think about how a group behaves when one member changes or fails.
✗ Incorrect
The ngForm directive aggregates all child controls. The form is valid only if every control is valid. The form is dirty if any control has been changed.