Hello, I do fields for editing an object in angular, I ran into a problem when fields already transferred in value are not processed when forms are submited, more precisely they are processed only when you edit them, here’s an example of how to deal with this

<form [formGroup]="myForm" (ngSubmit)="onSubmit(myForm)"> <input formControlName="title" type="text" class="form-control" placeholder="Название" value="{{ content?.title }}"/> <input formControlName="body" type="text" class="form-control" placeholder="Контент" value="{{ content?.body }}"/> <input type="submit" value="Редактировать"/> </form> 

  • Try working with the form this.myForm.get('title').setValue = yourAsyncValue in your instance-class this.myForm.get('title').setValue = yourAsyncValue
  • It helped, very grateful) - Victor

1 answer 1

When working with Data-Driven forms, to change the values ​​of the form, you must access the form instance created in the component class and change the values ​​via setValue() . In this example, it will look like:

 this.myForm.get('title').setValue = yourAsyncValue;