A
A
Artur Zagorsky2019-10-17 12:02:09
JavaScript
Artur Zagorsky, 2019-10-17 12:02:09

What is the correct way to set the value of a control in a @angular/forms reactive form?

There are many inputs in the form, the user enters values ​​in certain of them, and after clicking on submit, the values ​​of neighboring inputs are calculated based on these values.
The form model is created in the constructor using FormBuilder.group().
Here is an example:

form.controls['listingBrokerCommission'].setValue(sellingPrice * listingBrokerCommissionPercent / 100);
form.controls['estimatedSellersNetProceeds'].setValue(sellingPrice -listingBrokerCommission);

In the second line, the listingBrokerCommission gets the initialValue from the constructor, not the value received by the line above. Can you tell me what I'm doing wrong and how can I use the new listingBrokerCommission value?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Shvets, 2019-10-17
@artedza

Like this? https://ng-run.com/edit/O0xfejdvDIF5VGb3576J

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question