Answer the question
In order to leave comments, you need to log in
Angular2 how to write input data to sub-element?
To make it clearer.
There is a form. I am getting this form data. formGroup looks like this (pay attention to the contacts object, in the second case they are)
this.createForm = this.fb.group({
username: [''],
password: [''],
firstName: [''],
lastName: [''],
patronymic_name: [''],
birthday: [''],
gender: [''],
taxation_id: [''],
appointment: [''],
snils: [''],
telephones: ['', []],
emails: ['', []],
postals: ['', []]
});
this.createForm = this.fb.group({
username: [''],
password: [''],
firstName: [''],
lastName: [''],
patronymic_name: [''],
birthday: [''],
gender: [''],
taxation_id: [''],
appointment: [''],
snils: [''],
contacts: {
telephones: ['', []],
emails: ['', []],
postals: ['', []]
}
});
<form [formGroup]="createForm">
<section>
<label class="input">
<span>Email:</span>
<i class="icon-append fa fa-unlock-alt"></i>
<input type="text" name="firstName" placeholder="" formControlName="emails">
<b class="tooltip tooltip-bottom-right">{{'Needed to verify your account' | i18n }}</b>
</label>
</section>
<section>
<label class="input">
<span>Адрес проживания:</span>
<i class="icon-append fa fa-unlock-alt"></i>
<input type="text" name="firstName" placeholder="" formControlName="postals">
<b class="tooltip tooltip-bottom-right">{{'Needed to verify your account' | i18n }}</b>
</label>
</section>
</form>
Answer the question
In order to leave comments, you need to log in
A field inside a FormGroup can be either a FormControl or another FormGroup.
And then the form build will look like this:
this.createForm = this.fb.group({
...
contacts: this.fb.group({
telephones: ['', []],
emails: ['', []],
postals: ['', []]
})
});
<form [formGroup]="createForm">
<div formGroupName="contacts">
...
<input type="text" name="firstName" placeholder="" formControlName="emails">
...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question