【发布时间】:2016-04-18 15:05:42
【问题描述】:
我在这里找到了很多答案,但非常令人沮丧的是我无法执行它。首先解释一下我做了什么:
我创建了一个包含国家对象列表的数组。在 html 中,我循环遍历国家数组并将每个值添加到选择框。
我只想显示英国和美国,但是我的代码还有第三个选项(一个空选项)。
我怎样才能在数组中只包含 2 个值?这个answer should work,但它没有在 html 中显示正确的值。也许是因为我一直在使用 ng-repeat,但也许我应该像 this answer 建议的那样使用 ng-options?
请看下面我的代码。
控制器
this.countries = [
{name: "United Kingdom"},
{name: "United States of America"}
];
HTML
<select ng-model="ctrl.country">
<option ng-repeat="country in ctrl.countries" value="{{country.name}}">{{country.name}}</option>
</select>
【问题讨论】:
标签: javascript angularjs