I can't seem to work out how to easily set a value as the default value for a select dropdown list.
My current code
<select class="form-control" ngControl="modID" #modID="ngForm">
<option *ngFor="let module of modules" [value]="module._id">{{module.moduleName}}</option>
</select>
i have tried playing with the [selected] decorator but cannot work out how to get it to work.
given i have this modInst json object below:
{
"_id": 5,
"semester": "Tri 3",
"year": 2018,
"__v": 0,
"modID": [
{
"_id": 6,
"moduleLeader": "Jake Groves",
"moduleName": "Software Implementation",
"__v": 0
}
]
},
i would like the modInst.modID[0]._id to be selected from all the modules._id (modules) is whats populating the select list
any easy way of doing this?
edit:
i've tried adding [selected]="module._id == modInst.modID[0]._id"
but i get no success on it making it the selected value
i've also tried [ngValue]="modInst.modID[0]._id"
and it still doesn't select the module with id 6 in the list
one last addition ... i've tried a manual 'selected' and it still does not make a selected value upon load [selected]="module._id == '7'"