I have a piece of code that I used to bind my cost center information and set the default value.
Controller: In my controller, I have some logic to populate a list called costCenterList. It contains the following data:
$scope.costCenterList=[{ "costCenter": 111 }, { "costCenter": 112 }, { "costCenter": 113 }, { "costCenter": 114 }];
$scope.selected = $scope.costCenterList[0];
HTML:
<label class="item item-input">
<div class="input-label">Cost-center</div>
<select placeholder="Cost Center" ng-options="item.costCenter for item in costCenterList track by item.costCenter" ng-model="selected">
</select>
</label>
When trying to access the selected data in my controller using:
console.log("Selected costCenter:" + $scope.selected.costCenter);
Output:
Selected costCenter: 111
The output shows the default data that was initially presented in the form, not the data that I actually selected through the form. Any suggestions on how to address this issue?