Hi Everyone I\'m new to angular. Actually, I\'m trying to subscribe data from a service and that data, I\'m passing to form control of mine from (example, it\'s like an edit
Try this.
editqueForm = this.fb.group({
user: [this.question.user],
questioning: [this.question.questioning, Validators.required],
questionType: [this.question.questionType, Validators.required],
options: new FormArray([])
})
setValue and patchValue
if you want to set the value of one control, this will not work, therefor you have to set the value of both controls:
formgroup.setValue({name: ‘abc’, age: ‘25’}); It is necessary to mention all the controls inside the method. If this is not done, it will throw an error.
On the other hand patchvalue is a lot easier on that part, let’s say you only want to assign the name as a new value:
formgroup.patchValue({name:’abc’});