Look at the naming convention, I changed the names in my example a little to reflect the lower / upper case that we usually use;)
You are on the right track to use [ngValue] . Let your name bind the entire object, which we can then use in the type to show the corresponding type. Therefore, let us create a variable in which we will store the selected game, when the user selects a name from the drop-down list, let me call it selectedGame :
component:
selectedGame: Object = {};
Template:
<select [(ngModel)]="selectedGame" required> <option *ngFor="let game of games" [ngValue]="game">{{game.name}}</option> </select>
Now we have bound the entire object to selectedGame , so the input field will reflect that we are making changes, since we use selectedGame.type as a two-way binding for the input field. So your template will look like this:
<label>Name:</label> <select [(ngModel)]="selectedGame" required> <option *ngFor="let game of games" [ngValue]="game" > {{game.name}} </option> </select> <label>Type:</label> <input type="type"name="type" [(ngModel)]="selectedGame.type">
Here a
source share