Angular 2: Unable to get FormGroup dynamic work

I play with Angular 2 (rc4), but I am having a little problem.

I have a form built with help FormBuilderthat works well.

Since Plunker uses Angular RC0, you can get an example of what's wrong here . It is based on Angular quick start, so simple:

npm i
npm start

FormComponentaccepts an input Personthat is the person to edit. This input is dynamically provided by the parent FormComponent. When I click on a person, FormComponentsets a new form through ngOnChanges(). Why OnChanges? Because it is FormComponentupdated, not re-displayed.

So what's the problem?

Changes made to mine FormComponentare not tracked by the Angular form if I switch to another person.

How to play

Expected Behavior:

  • change name without switching to another person
  • submit the form
  • myForm.value contains a new name - as expected.

Problem:

  • select another user through App, FormComponentwill be updated correctly
  • change name
  • imagine
  • myForm.valuecontains the old name. I can’t update it.

What am I doing wrong?

Thank.

+4
source share

All Articles