Angular 2, dynamic forms; updateValue() do not update checkbox form control -


i'm building angular 2 (2.0.0-rc.4) application new form api (2.0.2) , i've got problem when i'm trying update checkbox form controls updatevalue().

this i've done:

i've built dynamic form new form api (based on section in cookbook: https://angular.io/docs/ts/latest/cookbook/dynamic-form.html). i've extended form class handle checkboxes:

export class formcontrolcheckbox extends formbase <string> {   controltype: string;   options: { key: string, value: string, checked: boolean } [] = [];   checked: boolean = false;    constructor(options: {} = {}) {     super( options );      this.controltype = "checkbox";     this.options = options['options'] || [];     this.checked = this.options[0].checked;   } } 

this looks when it's created:

new formcontrolcheckbox({     type: "checkbox",     label: 'a label',     name: "a-name",     value: "",     description: "a description",     options: [       {         label: 'a label',         name: "a-name",         checked: false       }     ],   }) 

when application loaded form controls created , grouped together, works fine , form submitted intended. had workaround make checkbox update on change , markup followed:

<input [formcontrolname]="control.key" [(ngmodel)]="control.checked" [id]="control.key" [type]="control.controltype" [attr.checked]="control.checked ? true : null" [value] = "control.checked" (change)="control.checked = $event.target.checked"> 

i've tried markup (it works fine):

<input [formcontrolname]="control.key" [(ngmodel)]="control.checked" [id]="control.key" [type]="control.controltype" [attr.checked]="control.checked ? true : null" [value] = "control.checked" (change)="control.checked = check.checked" #check> 

this problem occurs

i'm adding feature updates control values when form have been loaded (the user should able revisit page , update previous values). code below update control values.

for (var key in new_values) {   //the form control keys same key in list of new_values   this.form.controls[key].updatevalue(new_values[key]); //works text, select , option   this.form.controls[key].updatevalueandvalidity(); //not sure if needed?   this.form.controls[key].markasdirty(); } 

text, option , select inputs gets updated checkboxes unchanged. no errors or warnings. i've searched lot similar problems have not found similar problem or solution.

am missing obvious? or have had same problem , want share solution?

thanks!

solved problem changing values before creating control-groups (before it's possible change values (ex. x.value). solved problem not solve fact dynamically changes checkbox form controls not reflected in dom element.


Comments