Trying to populate a select option with data from a simple JSON array.
For example, I want to create a country selector. Each country in the array has an ID and a name, among other fields that are not needed. Essentially, I aim to set one value in the value=""
attribute and display another between the
<option>tags</option>
HTML Snippet
<div ng-controller="DemoCtrl">
<p>populate select options with ajax</p>
<select id="Country" name="Country" class="form-control" size="10"
ng-model ="chooseCountries">
<option ng:repeat="country in chooseCountries" value="{{country.id}}">
{{country.name}}
</option>
</select>
</div>
Javascript Snippet
'use strict';
function DemoSelectCtrl($scope) {
$scope.chooseCountries=[
{countryId : 1, name : "France - Mainland", desc: "some description" },
{countryId : 3, name : "Gibraltar", desc: "some description"},
{countryId : 3, name : "Malta", desc: "some description"}
];
});
I have combined everything in this JSFiddle. However, I feel like something is missing.