haya
haya

Reputation: 487

Bind object to FormGroup - ng2

I have an object contains data (for example: orderDetails) and I have FormGroup object bind to my object (orderDetails).

this.formGroup = this.formBuilder.group(this.orderDetails);

I want to change the object (ex. this.orderDetails.price = 15;) and to see it in the formGroup and in the view.

I can also access the formGroup this.formGroup.controls['price'].setValue(15); but it force me to write the field name without intellisense.

Is there any way to synchronize between the object and the formGroup? Thanks!

Upvotes: 1

Views: 1019

Answers (1)

Max Koretskyi
Max Koretskyi

Reputation: 105499

You can use ngModel binding to automatically synchronize between the model and the control:

<input type="text" formControlName="price" [(ngModel)]="orderDetails.price">

Upvotes: 1

Related Questions