Suppose I have the following managed model:
this.addressForm = this.formBuilder.group({ address: this.formBuilder.group({ placeId: [this.address.placeId], description: [this.address.description] }) });
And the following template:
<form [formGroup]="addressForm" (ngSubmit)="updateAddress()" novalidate> <div class="form-group"> <div class="input-group"> <input type="text" formControlName="address" placeholder="Type in you address" [ngbTypeahead]="chooseAddress" [inputFormatter]="addressFormatter" [resultFormatter]="addressFormatter" autocomplete="off" class="form-control"> </div> ... </form>
addressFormatter:
addressFormatter = param => param.description;
Say an address object with two properties: placeId and description .
It seems impossible to deal with formGroup (here address ) instead of formControl (here address.placeId ) and still pre-populate the form with one of the properties of the object (e.g. address.description ).
I get the following error:
Error. / UserAccountAddressComponent class UserAccountAddressComponent - built-in template: 8: 9 called: control.registerOnChange is not a function TypeError: control.registerOnChange is not a function
I was unable to display one property of the object in the field ( address.description ) and use another when I submit the form ( address.placeId ), while still having the opportunity to pre-fill the form with one of the property objects (here address.description ).
Can anybody help?
source share