In my Tv class, I have several string variables. One requirement is for the user to select an option from a DropDown list and input a value. This entered value should then be stored in the Tv class under a variable with a similar name to the selected option. Afterwards, the Tv object is sent to the BackEnd.
Definition of my Tv class:
export class Tv {
id: number;
brand: string;
model: string;
color: string;
display_technology: string;
screen_size: string;
refresh_rate: string;
weight: string;
condition: string;
inputs: string;
}
Description of my DropDown list:
<select class="form-control col-md-3">
<option *ngFor="let param of parameters">{{param}}</option>
</select>
<div class="col">
<input type="text" class="form-control" id="parameter" required>
</div>
Update: Functional code snippet.
<div class="row">
<select name="tvParam" class="form-control col-md-3" [(ngModel)]="selectedParam">
<option *ngFor="let param of parameters">{{param}}</option>
</select>
<div class="col">
<input type="text" class="form-control" name="tvParamValue" [(ngModel)] = "parameter" (change)="saveData()">
</div>
saveData(){
this.tv[this.selectedParam.toLocaleLowerCase()] = this.parameter;
}