我已经构建了这样的形式。
this.myForm = this.fBuilder.group({
openingHoursForm: this.fBuilder.array([])
});
this.openingHoursArray = data.body.OpeningHours;
this.openingHoursArray.forEach(element => {
(<FormArray>this.myForm.get('openingHoursForm')).push(this.fBuilder.group({
Id: [element.Id],
Heading: [element.Heading],
Subheading: [element.Subheading],
When: [element.When],
Times: [element.Times],
Emphasis: [element.Emphasis],
SortOrder: [element.SortOrder]
}));
});
但是如何在特定索引处修补“SortOrder”的值。我有这个,但它不起作用:
moveRowUp(currentIndex,fixture)
{
const control = <FormArray>this.myForm.controls['openingHoursForm'];
control.at(currentIndex)['SortOrder'].patchValue(currentIndex + 1);
console.log(this.myForm);
}
答案 0 :(得分:0)
试试这个
moveRowUp(currentIndex,fixture)
{
const control = this.myForm.get(['openingHoursForm',currentIndex,'SortOrder']) as FormControl;
control.patchValue(currentIndex + 1);
}
答案 1 :(得分:0)
这可能更容易做到,但最后我这样做了:
MediaQuery.of(context).viewInsets.bottom