Can someone help me set the values of a model driven form for data coming through http.
Here is the excerpt from service.ts
getExternalConnection(row_id){
return this._http.get(this._url + '/' + row_id)
.map(res=> res.json());
}
Here is the excerpt from component.ts
constructor(private _externalConnectionListService: ExternalConnectionListService,
private _route: ActivatedRoute, fb: FormBuilder
) {
this.externalConnectionForm = fb.group({
row_id : [''],
name: ['', Validators.required]
});
}
ngOnInit(): void {
this.id = this._route.snapshot.params["row_id"];
this._externalConnectionListService.getExternalConnection(this.id)
.subscribe( res=> {this.data = res;
this.externalConnectionForm.patchValue(this.data);
});
With this code I dont see any initial values in the form. However if I replace this.data in patchValue call manually with the entire string returned by the observable after removing the square brackets [], the form is populated fine.
How do I deal with this? This means patchValue is working fine, it just does not like the format of the input from this.data.