WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Form control not updated in zoneless #9549

@vatsake

Description

@vatsake

Reproduction link

ng-zorro doesn't compile in stackblitz

Error in /turbo_modules/ng-zorro-antd@20.4.2/fesm2022/ng-zorro-antd-input.mjs (366:856)
Cannot access 'NzInputDirective' before initialization

Steps to reproduce

In my gif below, I'm using the same formGroup.
If I change the "text component" via click, it will trigger resetForm()
In the dev window you can see the classes "ng-untouched ng-pristine ng-valid" but also "ant-input-status-error".

  rootFormGroup = inject(FormGroupDirective)

  constructor() {
    effect(() => {
      if (this.currentId !== this.component().uid) {
        this.currentId = this.component().uid
        this.resetForm()
      }
    })
  }

  resetForm() {
    this.form = this.rootFormGroup.control

    Object.keys(this.form.controls).forEach((key) => this.form.removeControl(key))
    this.form.addControl('text', this.fb.control(this.component().attributes.text, Validators.required))
    this.form.addControl('required', this.fb.control(this.component().attributes.required))
    this.form.addControl('placeholder', this.fb.control(this.component().attributes.placeholder))
    this.form.addControl('multiple_rows', this.fb.control(this.component().attributes.multiple_rows))
    this.form.get('text')!.updateValueAndValidity() // This doesn't do anything

  }

Image

What is expected?

Should validate

What is actually happening?

It doesn't

Environment Info
ng-zorro-antd 20.4.2
Browser Chrome

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions