如何将数组项推入表单组的数组属性
我的表单组定义为:
this.scheduleParentModel = this.fb.group({
startDate: ['', dateValidator()],
endDate: ['', dateValidator()],
frequency: [1, Validators.required],
repeatTime: ['', Validators.required],
frequencyInterval: this.fb.array([],),
}, { validator: this.dateLessThan('startDate', 'endDate') });
API调用后,我想将API的结果绑定到表格组scheduleparentModel
。 API还将fusity Interval
作为逗号分隔字符串返回。
我已将API结果绑定为:
this.scheduleParentModel.patchValue({
startDate: this.datepipe.transform(new Date(schedules.startdate), 'mediumDate'),
endDate: this.datepipe.transform(new Date(schedules.enddate), 'mediumDate'),
repeatTime: schedules.repeattime,
frequency: schedules.frequency
});
为了绑定到频率间隔
,我做到了:
let frequencyInterval = [...schedules.frequencyinterval.split(',').map(item => item.trim())];
const fInt = this.scheduleParentModel.controls.frequencyInterval as FormArray;
fInt.push(this.fb.group(frequencyInterval));
它变为:
{
"startDate": "Jun 24, 2022",
"endDate": "Jun 30, 2022",
"frequency": 8,
"repeatTime": "18:00",
"frequencyInterval": [{
"0": "5",
"1": "4",
"2": "3",
"3": "2",
"4": "1"
}]
}
但是,我希望输出为:
{
"startDate": "Jun 24, 2022",
"endDate": "Jun 30, 2022",
"frequency": 8,
"repeatTime": "18:00",
"frequencyInterval": ["5","4","3","2","1"]
}
计划对象:
{
"enddate": "2022-06-30T00:00:00",
"frequency": 8,
"frequencyinterval": "5, 4, 3, 2, 1",
"lastUpdateOn": "2022-06-18T09:41:26",
"message": "ffdsdewe",
"remindafter": false,
"remindtime": 0,
"repeattime": "18:00",
"scheduleid": 10,
"startdate": "2022-06-24T00:00:00",
"starttime": "",
"timezone": null,
"title": "reset donerecurring"
}
如何将数组项目推到形式组的属性。
I have a form group defined as:
this.scheduleParentModel = this.fb.group({
startDate: ['', dateValidator()],
endDate: ['', dateValidator()],
frequency: [1, Validators.required],
repeatTime: ['', Validators.required],
frequencyInterval: this.fb.array([],),
}, { validator: this.dateLessThan('startDate', 'endDate') });
After the API call, I wanted to bind the result from API into the form group scheduleParentModel
. API also returns the frequencyinterval
as a comma-separated string.
I have bind the api result as:
this.scheduleParentModel.patchValue({
startDate: this.datepipe.transform(new Date(schedules.startdate), 'mediumDate'),
endDate: this.datepipe.transform(new Date(schedules.enddate), 'mediumDate'),
repeatTime: schedules.repeattime,
frequency: schedules.frequency
});
for binding to the frequency interval
, I did, as:
let frequencyInterval = [...schedules.frequencyinterval.split(',').map(item => item.trim())];
const fInt = this.scheduleParentModel.controls.frequencyInterval as FormArray;
fInt.push(this.fb.group(frequencyInterval));
it becomes as:
{
"startDate": "Jun 24, 2022",
"endDate": "Jun 30, 2022",
"frequency": 8,
"repeatTime": "18:00",
"frequencyInterval": [{
"0": "5",
"1": "4",
"2": "3",
"3": "2",
"4": "1"
}]
}
however, i wanted the output as:
{
"startDate": "Jun 24, 2022",
"endDate": "Jun 30, 2022",
"frequency": 8,
"repeatTime": "18:00",
"frequencyInterval": ["5","4","3","2","1"]
}
Schedule objects:
{
"enddate": "2022-06-30T00:00:00",
"frequency": 8,
"frequencyinterval": "5, 4, 3, 2, 1",
"lastUpdateOn": "2022-06-18T09:41:26",
"message": "ffdsdewe",
"remindafter": false,
"remindtime": 0,
"repeattime": "18:00",
"scheduleid": 10,
"startdate": "2022-06-24T00:00:00",
"starttime": "",
"timezone": null,
"title": "reset donerecurring"
}
How to push the array items to the properties of form group.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将其用于绑定到
频率间隔
。您需要使用
控制
而不是group
use this for binding to the
frequency interval
.you need to use
control
instead ofgroup