I can't get this to work:
<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>
And in the controller I have:
$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 };
From what I have read this is how it should be done, but the initiation does not work. Everything else works as i should, and I can see that the variable ($scope.user.playerYears.value) does change when I select values from the dropdown-menu. Also the variable has the initiated value of 3, but the controller shows the first element as selected (-2).
I have tried to call a function and set the initiated value there but no effect with that either.
Can someone please explain how I can fix this.
You can fix it. Please, see jsfiddle. This does not work for angular 1.2.