I am developing Angular 4 Application, which have a dropdown with a default value populated. But my below code is not working for default
selection. It shows blank regardless of what I set via ngModel
.
<div class="form-group form-ctrl-display header-button-align">
<select name="selectDepartment" class="form-control form-control-sm"
[class.faded]="format.isEmpty(filter.Department)"
style="max-width: 94px"
[(ngModel)]="filter.Department"
placeholder="Department">
<option *ngFor="let department of filterViewData.Departments"
[ngValue]="department">
{{department.Name}}
</option>
</select>
{{filter.Department| json}}
</div>
I have double checked the json data and it looks Ok. Here is the screenshot
Already tried Angular 2 Dropdown Options Default Value but nothing works. Not sure what is the problem and whole day I cant figure out the reason.
Below is the json data:
filter. Department
{"DepartmentId":401,"Name":"Transport","IsActive":true}
fiterViewData. Departments
[{"DepartmentId":400,"Name":"IT","IsActive":true},
{"DepartmentId":401,"Name":"Transport","IsActive":true},
{"DepartmentId":402,"Name":"Admin","IsActive":true}]