Recall & Review
beginner
What is a
FormControl in Angular?A <code>FormControl</code> is a class that tracks the value and validation status of an individual form input element. It helps manage user input and form state.Click to reveal answer
beginner
How do you create a simple
FormControl in Angular?You create it by importing <code>FormControl</code> from <code>@angular/forms</code> and then initializing it like this: <code>const nameControl = new FormControl('');</code> This sets up a control with an empty initial value.Click to reveal answer
beginner
How can you get the current value of a
FormControl?You access the
value property of the FormControl. For example, nameControl.value returns the current input value.Click to reveal answer
beginner
What is the purpose of validators in a
FormControl?Validators check if the input value meets certain rules, like required fields or minimum length. They help keep the form data correct and useful.
Click to reveal answer
intermediate
How do you listen for changes in a
FormControl?You subscribe to the
valueChanges observable. For example: nameControl.valueChanges.subscribe(value => console.log(value)); This runs code whenever the input changes.Click to reveal answer
What does a
FormControl track in Angular?✗ Incorrect
A
FormControl tracks the value and validation status of a single form input.How do you create a new
FormControl with an initial value of 'hello'?✗ Incorrect
You create a
FormControl by calling new FormControl('hello') to set the initial value.Which property gives you the current value of a
FormControl?✗ Incorrect
The
value property holds the current input value of the FormControl.What is the role of validators in a
FormControl?✗ Incorrect
Validators ensure the input follows rules such as being required or having a minimum length.
How do you react to changes in a
FormControl value?✗ Incorrect
You subscribe to the
valueChanges observable to run code when the input changes.Explain what a
FormControl is and how you create one in Angular.Think about managing a single input field's data and rules.
You got /3 concepts.
Describe how you can check the current value and listen for changes in a
FormControl.One is a property, the other is an observable.
You got /2 concepts.