Challenge - 5 Problems
FormControl Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What is the initial value of this FormControl?
Consider the following Angular code snippet creating a FormControl. What will be the initial value of
nameControl.value?Angular
import { FormControl } from '@angular/forms'; const nameControl = new FormControl('Alice');
Attempts:
2 left
💡 Hint
Check what value is passed when creating the FormControl.
✗ Incorrect
The FormControl is initialized with the string 'Alice', so its value property starts as 'Alice'.
❓ state_output
intermediate2:00remaining
What is the value of
emailControl.value after update?Given this Angular FormControl, what will be the value of
emailControl.value after calling setValue('user@example.com')?Angular
import { FormControl } from '@angular/forms'; const emailControl = new FormControl(''); emailControl.setValue('user@example.com');
Attempts:
2 left
💡 Hint
setValue changes the FormControl's value.
✗ Incorrect
Calling setValue updates the FormControl's value to the new string provided.
❓ lifecycle
advanced2:00remaining
What happens when
markAsTouched() is called on a FormControl?In Angular, after calling
markAsTouched() on a FormControl, which of the following is true?Angular
import { FormControl } from '@angular/forms'; const control = new FormControl(''); control.markAsTouched();
Attempts:
2 left
💡 Hint
Touched means the user has focused and left the control.
✗ Incorrect
markAsTouched sets the touched property to true, indicating the control was visited.
📝 Syntax
advanced2:00remaining
Which option correctly creates a FormControl with a required validator?
Select the correct Angular code to create a FormControl with an initial empty string and a required validator.
Angular
import { Validators } from '@angular/forms';
Attempts:
2 left
💡 Hint
Validators go as the second argument in an array.
✗ Incorrect
The correct syntax passes the initial value first, then an array of validators as the second argument.
🔧 Debug
expert3:00remaining
Why does this FormControl's value not update on input?
Given this Angular template and component code, why does the FormControl's value not update when typing in the input field?
Component:
import { Component } from '@angular/core';
import { FormControl } from '@angular/forms';
@Component({
selector: 'app-email',
templateUrl: './email.component.html'
})
export class EmailComponent {
email = new FormControl('');
}
Template:
Angular
<input type="email" [formControl]="email" (input)="email.setValue($event.target.value)" />
Attempts:
2 left
💡 Hint
Using both [formControl] and (input) with setValue causes conflicts.
✗ Incorrect
Binding [formControl] already updates the value on input. Adding (input) with setValue causes redundant updates and can break the control's value syncing.