I have a Reactive form that group select on the left and input type number on the right and I want to get a value that combines this two.
For example
dynamicForms.html
<form novalidate (ngSubmit)="onSubmit(form.value)" [formGroup]="form">
<div fxLayout="row" fxLayoutGap="10px" *ngSwitchCase="'number'">
<mat-form-field *ngIf="prop.units !== [];" fxFlex="80px">
<mat-select placeholder="Unit" (change)="form.value.frequencies.unit = 'KHz';">
<mat-option *ngFor="let unit of prop.units" [value]="unit">
{{ unit }}
</mat-option>
</mat-select>
</mat-form-field>
<mat-form-field *ngSwitchCase="'number'" fxFlex="100" class="full_width">
<input
type="number"
matInput
[formControlName]="prop.key"
[placeholder]="prop.key"
[id]="prop.key"
[min]="prop.min"
[max]="prop.max"
value="{{prop.value}}">
<mat-icon *ngIf="prop.description" class="inp_description" matTooltip="{{prop.description}}" matTooltipShowDelay="500" matSuffix>help</mat-icon>
</mat-form-field>
</div>
</form>
<p>
<button mat-raised-button [disabled]="form.invalid" type="submit">Save</button>
</p>
What I get is:
frequencies: 58
And what I want on submit is this values.
frequencies: {
value: 58,
unit: 'KHz'
}
I try every trick I know in Anguar but nothink is work
