Angularjs 使用 json 填充选择选项

Rob*_*_UK 7 javascript select json populate angularjs

我希望使用基本 json 数组中的值填充选择选项。

我的例子是一个国家选择。每个国家/地区都有一个 id 元素和一个名称以及我可以忽略的其他字段。基本上我想说在value=""字段中放置一个值,在字段之间放置另一个值<option>tags</option>

html 片段

<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>
Run Code Online (Sandbox Code Playgroud)

javascript 片段

'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"}
    ];  

});
Run Code Online (Sandbox Code Playgroud)

我把它放在一起js fiddle .. 我想我错过了一些东西

小智 3

  1. angular.module('ui.bootstrap.demo', ['ui.bootstrap'])- 确保你有 ui.bootstrap。阅读如何安装它http://angular-ui.github.io/bootstrap/
  2. 这是您更新的 jsfiddle http://jsfiddle.net/e31k5e6L/1/