Reputation: 2061
I am new to Bootstrap and I'm Working with the latest Bootstrap 3.3.7. I'm trying to display the selected value when the user selects one of the options. but using my below code its not displaying selected value can some one help me please
<div class="form-group">
<label for="department">DepartMent</label>
<select id="department" name="department" [(ngModel)]="department" class="form-control">
<option *ngFor="let dept of departments" [value]="dept">
{{dept.name}}
</option>
</select>
</div>
departments: Department[] = [
{ id: 1, name: 'HR' },
{ id: 2, name: 'IT' },
{ id: 3, name: 'DEV'},
{ id: 4, name: 'MG' }
]
Upvotes: 0
Views: 1072
Reputation: 49
Change [value] to value and "dept.id" to {{dept.id}}
<div class="form-group">
<label for="department">DepartMent</label>
<select id="department" name="department" [(ngModel)]="department" class="form-control">
<option selected disabled>Select a Department</option>
<option value={{dept.id}} *ngFor="let dept of departments">
{{dept.name}}
</option>
</select>
</div>
Upvotes: 1