I have two formControl
inside a formGroup
inside of a formArray
like this:
<form [formGroup]="fg" (ngSubmit)="SaveInput()">
<ul formArrayName="comments">
<div *ngFor="let cm of fg.get('comments')['controls']">
<input readonly formControlName="xts">
<input type="text" formControlName="xtxt">
</div>
</ul>
</form>
When data from xtxt
is saved in DB and returns a timestamp, I'd like to have this timestamp value displayed on xts
. I'm able to set the value in two places and confirmed are good. But it's not reflected in display
SaveInput()
{
...
this.mySvc.saveInput(param)
.subscribe
(
good =>
{
let x =<FormGroup>this.fg.get(selectionString);
x.value.xts = good.timestamp; // <-- place 1
x.controls.xts.value = good.timestamp; // <-- place 2
}
);
}
CodePudding user response:
you shouldn't set value directly but use methods. I believe patchValue
suits your case the best.
Cheers!