My solution involves avoiding the use of ng-hide
to prevent conflicts with simultaneous model reading and writing in your AngularJS application. Instead, I have created a different approach that accomplishes the desired functionality. Check out the following demo to see it in action:
Markup Code
<div ng-app ng-controller="Controller">
<select ng-model="selectedOption" ng-options="o for o in options"></select>
{{selectedOption}}
</div>
Controller Code
function Controller ($scope) {
var initialOptions = ['Apple', 'Banana', 'Orange'];
$scope.options = initialOptions;
$scope.selectedOption = $scope.options[1]; // set default option to "Banana"
$scope.$watch('selectedOption', function( val ) {
if( val === 'Apple' ) {
$scope.options = ['Apple', 'Orange'];
} else {
$scope.options = initialOptions;
}
});
}