Here is my UI
https://i.stack.imgur.com/NlBNA.png
I want my form value like this {color :"red"} where **mat-selects value is color** and **input field is red**. When I will change mat-select
s value the key that means color will be changed too.
Let say if I change mat-select`s value from the color to storage then.
My OutPut should be {storage:"red"}
Let say if I change the input field`s value from the red to "250Gb" then.
My OutPut should be {storage:"250Gb"}
how to solve this problem best way possible.Thanks for your help
MY HTML:
<form [formGroup]="itemEntryForm" (submit)="onSaveitem()">
<div>
<mat-form-field appearance="outline" class="full-width-input">
<mat-label >Attribute :</mat-label>
<mat-select>
<mat-option *ngFor="let attribute of attributes" [value]="attribute.name">{{ attribute.name }}</mat-option>
</mat-select>
<mat-label><mat-icon>branding_watermark</mat-icon> <b>*Attribute </b> <i> label</i></mat-label>
</mat-form-field>
</div>
<div>
<mat-form-field class="full-width-input">
<mat-label >Attribute Value :</mat-label>
<input matInput name="item_attribute" placeholder="Color ,Storage" formControlName="item_attribute">
<mat-error *ngIf="itemEntryForm.get('item_attribute').invalid">Attribute</mat-error>
</mat-form-field>
</div>
<div>
</form>
MY Ts File:
export class ItemEntryComponent implements OnInit {
itemEntryForm:FormGroup;
taxes = [{name:"tax"},{name:"tax2"}]
constructor(private _formbuilder:FormBuilder) { }
ngOnInit(): void {
this.itemEntryForm=this._formbuilder.group({
type : ['Goods'],
item_name : ['',Validators.required],
description : ['',Validators.required],
unit : ['pc',Validators.required],
tax : ['',],
manufacturer : ["",],
brand : ['',],
item_attribute : ['',],
item_attribute2: ['',],
image : ['',],
})
}
onSaveitem(){
console.log( this.itemEntryForm.value)
}
}