MonteCristo MonteCristo - 1 year ago 95
Javascript Question

update number field value in nested angular 2 component

I have a nested/sub formgroup. It has a number field that need to update by clicking a button. I can update the value itself but I can't get the field updated.

How do I fix it?

here is the plnkr

increment() {
this.adressForm.value.age = this.number++;


thanks in advance.

Answer Source

In AddressComponent change your code to

increment() {
  let currentAgeValue : number = this.adressForm.controls.age.value;
  this.adressForm.controls.age.setValue(currentAgeValue + 1);

Working forked Plunker

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download