I am encountering an issue with this code:
<div class="year-divider">
<select style="width:70px;" class="form-control year-selector"
id="{{'playerYearSelector'}}"
name="playerCurrYear" data-ng-model="user.playerYears.value"
data-ng-init="user.playerYears.value = user.playerYears.valueIdx[user.initYearIdx]">
<option data-ng-repeat="v in user.playerYears.valueIdx"
value="{{user.playerYears.valueIdx[v]}}"
data-ng-disabled="user.playerYears.disabled[v]">
{{user.playerYears.strValues[v]}}
</option>
</select>
</div>
In my controller, I have the following setup:
$scope.user = {};
$scope.user.initYearIdx = 3;
var disabled = [ false, false, false, false, false, false, false, false, false, false, true ];
var strValues = [ "-2", "-1", "0", "1", "2", "3", "4", "5", "6", "7", "8" ];
var valueIdx = [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ];
var values = [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ];
$scope.user.playerYears = {
"value": 3,
"values": values,
"valueIdx": valueIdx,
"strValues": strValues,
"disabled": disabled };
Despite following what I've read on how to initialize it, the initiation process isn't working as expected. The rest of the functionality works fine, and I can see that the variable ($scope.user.playerYears.value) changes when selecting dropdown options. However, even though the variable is set to an initial value of 3, the controller shows the first element (-2) as selected.
I've attempted calling a function to set the initial value, but that hasn't yielded any results either.
If anyone could provide guidance on resolving this issue, I would greatly appreciate it.