I am attempting to create an array that contains arrays within it.
This array is intended for a dynamic form functionality, where the user can add a new section and push the array of control fields to the main array. Angular2 then generates this dynamically.
Unfortunately, I'm encountering the following error message:
Error:(43, 41) TS2339: Property 'push' does not exist on type 'AbstractControl'.
Below is my code snippet:
addDesign(){
this.addForm.controls['design'].push(this.fb.group({
name: this.fb.control(null, Validators.required),
a1: this.fb.control(null, Validators.required),
a2: this.fb.control(null, Validators.required),
a3: this.fb.control(null, Validators.required),
a4: this.fb.control(null, Validators.required),
a5: this.fb.control(null, Validators.required),
maxMark: this.fb.control(null, Validators.required)
}));
}
Constructor function initializing the form:
constructor(private fb: FormBuilder, private auth: Auth, private authHttp: AuthHttp) {
this.addForm = fb.group({
name: fb.control(null, Validators.required),
assignID: fb.control(null, Validators.required),
design: new ControlArray([])
})
}
I have attempted
(<Control>this.addForm.controls['design']).push
as suggested in Angular2 issue 5871, but unfortunately, it did not resolve the problem.
The framework I am utilizing includes TypeScript and Angular2 beta.17