Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 生成窗体时控件和抽象控件出错_Angular_Typescript_Angular9 - Fatal编程技术网

Angular 生成窗体时控件和抽象控件出错

Angular 生成窗体时控件和抽象控件出错,angular,typescript,angular9,Angular,Typescript,Angular9,我有以下表格: this.myForm = new FormGroup({ points: new FormArray([ new FormGroup({ date: this.date, startTime: new FormControl(null, Validators.required), endTime: new FormControl(null, V

我有以下表格:

this.myForm = new FormGroup({
        points: new FormArray([
            new FormGroup({
                date: this.date,
                startTime: new FormControl(null, Validators.required),
                endTime: new FormControl(null, Validators.required),
            }),
            new FormGroup({
                date: this.date,
                startTime: new FormControl(),
                endTime: new FormControl(),
            }),
            new FormGroup({
                date: this.date,
                startTime: new FormControl(),
                endTime: new FormControl(),
            })
        ]),
    });
for (const group of (this.myForm.get('points') as FormArray).controls) {
            console.log(group);
            if (group.controls.date !== null) {
                if (group.controls.date.value !== null) {
                    group.controls.startTime.setValue(
                        group.controls.date.value + ' ' + group.controls.startTime.value
                    );
                    group.controls.endTime.setValue(
                        group.controls.date.value + ' ' + group.controls.endTime.value
                    );
                    group.controls.date.setValue(group.controls.date.value);
                }
            }
        }
当我提交时,我有以下表格:

this.myForm = new FormGroup({
        points: new FormArray([
            new FormGroup({
                date: this.date,
                startTime: new FormControl(null, Validators.required),
                endTime: new FormControl(null, Validators.required),
            }),
            new FormGroup({
                date: this.date,
                startTime: new FormControl(),
                endTime: new FormControl(),
            }),
            new FormGroup({
                date: this.date,
                startTime: new FormControl(),
                endTime: new FormControl(),
            })
        ]),
    });
for (const group of (this.myForm.get('points') as FormArray).controls) {
            console.log(group);
            if (group.controls.date !== null) {
                if (group.controls.date.value !== null) {
                    group.controls.startTime.setValue(
                        group.controls.date.value + ' ' + group.controls.startTime.value
                    );
                    group.controls.endTime.setValue(
                        group.controls.date.value + ' ' + group.controls.endTime.value
                    );
                    group.controls.date.setValue(group.controls.date.value);
                }
            }
        }
工作正常,但当我尝试
ng build--prod
时,出现错误:
类型“AbstractControl”上不存在属性“controls”
。如何访问FormArray中FormGroup的控件


提前感谢。

问题是您必须将组专门转换为FormGroup:

for (const group of (this.myForm.get("points") as FormArray).controls as FormGroup[]) {

也许这可以通过专门将组强制转换为FormGroup来解决吗?@GeckoIT我试过了,但没有结果(const group of(this.myForm.get(“points”)作为FormArray)。控件作为FormGroup[]){…似乎在我这边起了作用。是的!谢谢