-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating
Learning Angular - Fifth Edition
By :
The state of an Angular form differs between template-driven and reactive forms. In the former, the state is a plain object, whereas in the latter, it is kept in the form model. In this section, we will learn about the following concepts:
We will start by exploring how we can change the form state.
Working with the form state in template-driven forms is relatively easy. We must interact with the component property bound to the ngModel directive of a form control.
In reactive forms, we can use the value property of a FormControl instance or the following methods of the FormGroup class to change values in the whole form:
setValue: Replaces values in all controls of the formpatchValue: Updates values in specific controls of the formThe setValue method accepts an object as a parameter that contains key-value pairs for all form controls...