我有一组默认值的下拉菜单,例如"选择团队......"。这些值不是与ng-model
绑定的模型的一部分,因为它们在该上下文中无意义。
问题是,在用户选择了他们的值后,我想清除表单。我尝试将绑定模型设置为空对象并且为null但是在这两种情况下都不会将下拉恢复为"选择..."默认值。
我的下拉状态如下:
<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>
我想在用户点击&#34;取消&#34;时将其清除回默认值。控制器中的ng-click
函数如下所示:
$scope.cancelStakeholder = function () {
$scope.showStakeholderFields = false;
$scope.selectedDepartment = {};
$scope.selectedTeam = {}; //also tried setting these to null
$scope.selectedRep = {};
}
唯一能做的就是:
document.getElementById('ddlStakeholderTeam').selectedIndex = 0;
虽然看起来像黑客。这是唯一可行的方法吗?