I found the bug, the problem was that I was passing the same reference in
the form group her is what i changed:
//question-control.service.ts
toFormGroup(formelements: QuestionBase<any>[] ) {
let group:any = {};
formelements.forEach(element => {
if(element.controlType === "array"){
let arr:any[] = [];
let locobj = {};
element["options"].forEach((option:any) => {
option["element"].forEach((e:any) =>{
locobj[e.key] = e.value || '';
});
arr.push(new FormGroup(this.getFormControlObject(
locobj)));
});
group[element.key] = new FormArray(arr);
}else{
group[element.key] = element.required ? new FormControl(
element.value || '', Validators.required)
: new FormControl(element.value
|| '');
}
});
return new FormGroup(group);
}
private getFormControlObject(keys){
let retobj = {};
Object.keys(keys).forEach(function(key) {
retobj[key] = new FormControl(keys[key]);
});
return retobj;
}
Hier is a working plunker
http://plnkr.co/edit/4IMKdLKE51n41jzYY8sU
Am Mittwoch, 21. September 2016 13:48:02 UTC+2 schrieb Sheki Shral:
>
> Hi!
> I have tried to extend the app that's published on
> https://angular.io/docs/ts/latest/cookbook/dynamic-form.html so I can
> have an array-forms too, I can show the array fields but when I write
> something down (and submit) the values are always written on the last array
> child, hire is my plunker http://plnkr.co/edit/QcCN2I
>
> Best regards
> Shefki
>
--
You received this message because you are subscribed to the Google Groups
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.