简单来说,我有一个绑定到FormArray的表。有一个输入框,它将接受两个值,一个来自同一行,另一个作为“默认”值。我想对这两个值进行计算,并使用从结果中得出的值。
在HTML中使用value
属性当然是行不通的,因为当我console.log
formControl时,该值为0。
我的HTML:
<ng-container formArrayName="cap_values">
<tbody *ngFor="let item of capValues.controls; let i=index" [formGroupName]="i">
<tr>
<td><input type="number" formControlName="fdnTotalShares"
(keyup.enter)="getFdnTotalShares(fdnVal.value)">
</td>
<td><input style="border: none; text-align: center" formControlName="fdnSharesPercent"
value="{{Math.ceil(((100 / this.sumFdnTotalShares()) * this.capValues.value[i].fdnTotalShares) * 100.0) / 100.0 || 0}}"
readonly="readonly">
</td>
</tr>
</tbody>
ts:
this.form = this.fb.group({
fdnUnitPrice: [''],
esopUnitPrice: [''],
seedUnitPrice: [''],
cap_values: this.fb.array([this.fb.group({
name: '',
fdnTotalShares: '',
fdnSharesPercent: '',
fdnVal: '',
esopNewShares: '',
esopTotalShares: '',
esopSharesPercent: '',
esopTotalShareDiluted: '',
esopSharesPercentDiluted: '',
esopVal: '',
seedNewShares: '',
investment: '',
seedTotalShares: '',
seedSharesPercent: '',
seedSharesDiluted: '',
seedSharesPercentDiluted: '',
seedTotalVal: ''
}
)])
})
get capValues() {
return this.form.get('cap_values') as FormArray;
}
在这种情况下是否可以使用patchValue?我需要获取索引处的值,然后执行计算。如果我不够清楚的话,抱歉。