то, что я пытаюсь сделать, это сделать выборку, которая читает текст из данных json. Я как-то не могу прочитать ценность, и я не уверен, почему.
Вот мой код
Мой раскрывающийся список:
<label class="item item-input item-select">
<b class="input-label">Claim Type:</b>
<select ng-model="claimType" required>
<option value="Select claim" title="Select Claim" selected disabled>Claim Type</option>
<option ng-repeat="claim in claimType " value="{{claim.value}}"
ng-selected="{{claim.value== claimType}}">
{{claim.text}}
</option>
</select>
</label>
Мой Json Object
angular.module('app')
.factory('WebApi', function () {
var claimType = [{
value: "Car",
text: "Car",
}, {
value: "Boat",
text: "Boat",
}, {
value: "Others",
text: "Others"
}]
})
//Display 50 items randomly
var tempData = [];
for (var i = 0; i < 50; i++) {
var selectedClaimType = claimType[Math.floor((Math.random() * claimType.length))];
tempData.push({
claimType: selectedClaimType.text,
})
};
return {
getClaimTypes: function () {
return selectedClaimType.text;
},
}
В моем контроллере я позвонил
$scope.claimType = WebApi.getClaimTypes();
Вы можете использовать ng-options
для управления списком выбора.
<label class="item item-input item-select">
<b class="input-label">Claim Type:</b>
<select ng-model="claimType" required
ng-options="transport.text for transport in traffic">
<option value="" title="Select Claim" selected disabled>Claim Type</option>
</select>
</label>
Это привяжет выбранный transport
к claimType
. Если вы хотите, чтобы claimType
присваивал значение transport.value
, вы можете:
<label class="item item-input item-select">
<b class="input-label">Claim Type:</b>
<select ng-model="claimType" required
ng-options="transport.text as transport.value for transport in traffic">
<option value="" title="Select Claim" selected disabled>Claim Type</option>
</select>
</label>
tempData
иtempData
в него некоторые значения, но я не вижу, где вы использовали этот «случайный» массив в привязке selectlist ....