Как мне сбросить список выбора в AngularJS и отследить?
У меня есть список выбора.
<select id="search.month"
ng-model="search.month"
class="form-control"
ng-options="item as item.name for item in months track by item.id">
</select>
Я сбросил список
$scope.reset = function () {
$scope.search = {reportType: 0, month: 0, year: 0 };
};
Ничего не произошло. AngularJS 1.5.8
2 ответа
Решение
В версии 1.4 + AngularJ есть ошибка. По крайней мере, до 1,5,8 в моем опыте.
Сбросить список вручную.
$scope.reset = function () {
$scope.search = {reportType: 0, month: 0, year: 0 };
// Manually reset.
// https://github.com/angular/angular.js/issues/14892
$('#search\\.month').find('> option').each(function() {
$(this).removeAttr('selected');
});
$('#search\\.year').find('> option').each(function() {
$(this).removeAttr('selected');
});
};
Вам нужно вызвать эту функцию:
$scope.resetDropDown = function() {
$scope.temp = $scope.search.month; // Before reset select box, get selected value
$scope.search.month = "";
}