Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

表单模型再次赋值时的BUG(bug:When the form model was again assignment) #106

Closed
myepoch opened this issue Aug 21, 2017 · 5 comments

Comments

@myepoch
Copy link

myepoch commented Aug 21, 2017

当表单模型再次被赋值的时候报错(When the form model was again assignment,error) :
’ERROR Error: There is no FormControl instance attached to form control element with name: 'email'

  //CN: 初始化表单模型
 // EN: Initialization form model
  ngOnInit() {
    this.validateForm = this.fb.group({ 
      email            : [ '', [ Validators.email ] ],
    });
  }
  // CN:当页面文本框失去焦点时,表单模型再次赋值
  // EN:When the nz-input loses focus, again assignment form model
  public onIdCardChange (form: any): void { 
    this.validateForm = this.fb.group({
      email            : [ 'hello@nz-zorro.com', [ Validators.email ] ],
    });
  }

CN:以下是页面部分代码
EN:html code

<nz-root>
  <form nz-form [formGroup]="validateForm" (ngSubmit)="_submitForm()">
    <div nz-form-item nz-row>
      <div nz-form-control>
        <nz-input [nzSize]="'large'" formControlName="email" [nzId]="'email'" (nzBlur)="onIdCardChange(validateForm.controls)"></nz-input>
      </div>
    </div>
  </form>
</nz-root>
@vthinkxie
Copy link
Member

It's an angular problem, please use setValue or patchvalue to manipulate form value.
https://angular.cn/guide/reactive-forms#使用setvalue和patchvalue来操纵表单模型
Please make sure you fully understand the usage of Reactive forms.

@myepoch
Copy link
Author

myepoch commented Aug 21, 2017

你好,但是原生的ANGULAR响应式表单的input是没问题的:
(hi,The original ANGULAR , input is no problem:)

<input id="email" name="email" formControlName="email" (blur)="onIdCardChange(validateForm.controls)" class="form-control">

@vthinkxie
Copy link
Member

vthinkxie commented Aug 21, 2017

Hi @myepoch
please use follow code as a temp solution. thanks.

this.validateForm.controls['email'].setValue('hello@nz-zorro.com');

@vthinkxie
Copy link
Member

related #114

@lock
Copy link

lock bot commented Feb 19, 2019

This thread has been automatically locked because it has not had recent activity. Please open a new issue for related bugs and link to relevant comments in this thread.

@lock lock bot locked as resolved and limited conversation to collaborators Feb 19, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants