I am struggling with controlling a <select>
element using both ng-model
and ng-options
:
<select ng-model="user.option"
ng-options="value.label for (key, value) in data.options">
<option value="">Select value</option>
</select>
The options are structured in an object:
$scope.data.options = {
one: { label: 'one' },
two: { label: 'two' }
};
When I try to change the selected option from the controller, it only works in a specific scenario:
$scope.user.option = $scope.data.options['two'];
Complications arise when I attempt to utilize a variable master
to set $scope.user
:
$scope.master.option = $scope.data.options['two'];
$scope.user = angular.copy ($scope.master);
Unfortunately, this approach does not yield the expected result, as the <select>
element continues to display Select value
. Strangely, other elements are updated correctly.
What could be the issue in my implementation?
I have created a fiddle for better understanding, which can be accessed here.