You should also do this:
data: Observable<any>; ngOnInit():any { this.data = this._dataService.getAllData(); this.data .map((data) => { return this._formBuilder.group({ username: [ this.data.username, Validators.compose([this.usernameValid]) ] }) .subscribe((userForm) => { this.userForm = userForm }) }
Then, in your template, use the async channel as follows:
<form *ngIf="data | async" [formGroup]="userForm"> //...// </form>
Thus, there is no need to call updateValue() , and this simplifies the work if you have many different fields for which all default values ββare set from observables.
unitario
source share