Cannot read property '_syncPendingControls' of undefined angular 6

12,388

The problem is in initializing form control name proof in ngOnInit function

you need to update this initialization as follow

this.businessForm.controls.proof.patchValue(this.defaultValue);
Share:
12,388
Gaurav Kumar Singh
Author by

Gaurav Kumar Singh

Lead Software Engineer | Frontend

Updated on December 07, 2022

Comments

  • Gaurav Kumar Singh
    Gaurav Kumar Singh over 1 year

    I'm getting an error on form submit in angular 6

    my code is

    <form [formGroup]="businessForm" (ngSubmit)="submitForm()" id="bus-form">
        ....// some inputs
        <button type=submit>Next</button>
    </form>
    

    component

    businessForm = this.fb.group({
        proof: ['', Validators.required]
    });
    defaultValue;
    
    constructor(private fb: FormBuilder){}
    ngOnInit() {
        this.businessForm.controls.proof = this.defaultValue;
    }
    submitForm() {}
    

    error is

    ERROR TypeError: Cannot read property '_syncPendingControls' of undefined
        at VM42524 account-setting-account-setting-module~landing-landing-module~registration-registration-module.js:3292
        at VM42524 account-setting-account-setting-module~landing-landing-module~registration-registration-module.js:3344
        at VM42524 account-setting-account-setting-module~landing-landing-module~registration-registration-module.js:3310
        at Array.forEach (<anonymous>)
        at FormGroup.push.../node_modules/@angular/forms/fesm5/forms.js.FormGroup._forEachChild (VM42524 account-setting-account-setting-module~landing-landing-module~registration-registration-module.js:3310)
        at FormGroup.push.../node_modules/@angular/forms/fesm5/forms.js.FormGroup._reduceChildren (VM42524 account-setting-account-setting-module~landing-landing-module~registration-registration-module.js:3344)
        at FormGroup.push.../node_modules/@angular/forms/fesm5/forms.js.FormGroup._syncPendingControls (VM42524 account-setting-account-setting-module~landing-landing-module~registration-registration-module.js:3291)
        at VM42524 account-setting-account-setting-module~landing-landing-module~registration-registration-module.js:3292
        at VM42524 account-setting-account-setting-module~landing-landing-module~registration-registration-module.js:3344
        at VM42524 account-setting-account-setting-module~landing-landing-module~registration-registration-module.js:3310
    

    if anyone getting this error please help, Thanks in advance.

    • Sachila Ranawaka
      Sachila Ranawaka over 5 years
      show the component