I have a set of drop downs with default values like "Select Team...". These values are not part of the model bound with ng-model
since they're meaningless in that context.
The problem is, after a user has selected their values I want to clear the form. I tried setting the bound models to an empty object and null but in neither case do the drop downs revert to their "Select..." default values.
My drop downs look like this:
<select class="form-control input-sm" id="ddlStakeholderTeam"
ng-change="updateSelectedTeam(selectedTeam);"
ng-model="selectedTeam"
ng-options="t as t.TeamName for t in (teamList | filter: filterTeams) track by t.TeamId">
<option value="" selected disabled hidden>Select Team...</option>
</select>
I want to clear it back to it's default value when the user clicks "Cancel". My ng-click
function in the controller looks like this:
$scope.cancelStakeholder = function () {
$scope.showStakeholderFields = false;
$scope.selectedDepartment = {};
$scope.selectedTeam = {}; //also tried setting these to null
$scope.selectedRep = {};
}
The only thing that's worked is to put in a line like:
document.getElementById('ddlStakeholderTeam').selectedIndex = 0;
Seems like a hack though. Is this the only method that will work?