diff --git a/guides/creating-a-custom-form-field-control.md b/guides/creating-a-custom-form-field-control.md index a4b66adf0ecb..3911d17073ab 100644 --- a/guides/creating-a-custom-form-field-control.md +++ b/guides/creating-a-custom-form-field-control.md @@ -357,14 +357,14 @@ ngDoCheck() { } private updateErrorState() { - const parent = this._parentFormGroup || this.parentForm; + const parentSubmitted = this._parentFormGroup?.submitted || this._parentForm?.submitted; + const touchedOrParentSubmitted = this.touched || parentSubmitted; - const oldState = this.errorState; - const newState = (this.ngControl?.invalid || this.parts.invalid) && (this.touched || parent.submitted); + const newState = (this.ngControl?.invalid || this.parts.invalid) && touchedOrParentSubmitted; - if (oldState !== newState) { + if (this.errorState !== newState) { this.errorState = newState; - this.stateChanges.next(); + this.stateChanges.next(); // Notify listeners of state changes. } } ```