Here's the process I've been using to subscribe and update a reactive form based on observable data.
Maybe there is a way to solve the problem without subscribing to the observable and changing the value.
@Component({ selector: 'app-my-component', template: ` <form [formGroup]="myForm"> <input formControlName="name" /> <input formControlName="email" /> </form> `, }) export class MyComponent implements OnInit { myForm: FormGroup; constructor(private fb: FormBuilder, private ds: DataService) {} ngOnInit() { this.myForm = this.fb.group({ name: '', email: '', }); ds.data$.subscribe((data) => { this.myForm.setValue({ name: data.name, email: data.email, }); }); } }
Typically, one way to eliminate subscriptions is to use an asynchronous pipe in a wrapper
The form itself can handle user updates within NgOnInit or NgOnChanges (if there are likely to be multiple updates and setting the form values is important in that case)
Note: Some very cutting-edge Angular features are used in this example. You can follow the same pattern, but you don't necessarily need to use every feature