I created a reactive form on angular2 +, and after filling in, the data was saved to the browser, but if you refresh the page with the form, the data match up and the validity of the form does not change until you click on the form with the mouse. How to fix it?

    1 answer 1

    ngAfterContentInit() { this.validateAllFormFields(this.form); } validateAllFormFields(formGroup: FormGroup) { Object.keys(formGroup.controls).forEach(field => { const control = formGroup.get(field); if (control instanceof FormControl) { control.markAsTouched({ onlySelf: true }); } else if (control instanceof FormGroup) { this.validateAllFormFields(control); } }); } 
    • window.onload = () => {this.validateAllFormFields (this.form); }; does not work - Denis Podolyachenko
    • You need to call this method in ngAfterContentInit () {} - Jamshed
    • not work out, this problem in the browser is chrome. I tied with a two-way binding field, the login field is auto-filled normally, but the password is undefined until you click somewhere. This is a browser problem - Denis Podolyachenko
    • Most likely the problem with changeDetection - Anton Evseev