I have selected value coming from back end in JSON and i have select element content coming from back end in the same JSON also.
Problem is that selected value is not selected in the select element, but binding works fine when i select new element.
I tried several approaches (option element ng-repeat, ng-option) all with same result. Selected value which is in data.cruiseCategoryId was not selected in select element.
My app.js
var app = angular.module('plunker', []);
app.controller('MainCtrl', function($scope) {
$scope.name = 'World';
$scope.data = {
cruiseCategoryDropdownOptions: [{
disabled: false,
group: null,
selected: false,
text: "Interior Cabin Bella",
value: "6"
}, {
disabled: false,
group: null,
selected: false,
text: "Interior Cabin Fantastica",
value: "7"
}, {
disabled: false,
group: null,
selected: false,
text: "Oceanview Cabin Fantastica",
value: "8"
}, {
disabled: false,
group: null,
selected: false,
text: "Balcony Bella",
value: "9"
}, {
disabled: false,
group: null,
selected: false,
text: "Balcony Fantastica",
value: "10"
}, {
disabled: false,
group: null,
selected: false,
text: "Balcony Aurea",
value: "11"
}, {
disabled: false,
group: null,
selected: false,
text: "Balcony Wellness",
value: "12"
}, {
disabled: false,
group: null,
selected: false,
text: "Suite Fantastica",
value: "13"
}, {
disabled: false,
group: null,
selected: false,
text: "Suite Aurea",
value: "14"
}, {
disabled: false,
group: null,
selected: false,
text: "Suite Yacht Club Deluxe",
value: "15"
}],
cruiseCategoryId: 10
}
});
My html
selected value: {{data.cruiseCategoryId}}
<select class="form-control"
name="cruiseCategoryId"
id="cruiseCategoryId"
ng-options="i.value as i.text for i in data.cruiseCategoryDropdownOptions track by i.value"
ng-model="data.cruiseCategoryId">
</select>
Problem plunker: https://plnkr.co/edit/vQxdDA