使用ng重复或ng选项和删除空白选项选择长方体角度
Select box angular using ng-repeat or ng-options and removing blank option
我在这里找到了很多答案,但令人沮丧的是,我无法执行它。首先解释我所做的:
我已经创建了一个带有国家对象列表的数组。在html中,我循环浏览countries数组,并将每个值添加到一个选择框中。
我只想展示英国和美国,但我的代码还有第三个选项(空选项)。
如何在数组中只包含2个值?这个答案应该有效,但它没有在html中显示正确的值。也许是因为我一直在使用ng重复,但也许我应该像这个答案所建议的那样使用ng选项?
请参阅下面的代码。
控制器
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>
要删除空选项,您需要在加载此页面时为控制器中的ng-model="ctrl.country"
值分配country
,以显示默认的选定值。
类似:
this.countries = [
{name: "United Kingdom"},
{name: "United States of America"}
];
this.country = this.countries[0].name; // initially show "United Kingdom"
或需要创建另一个具有empty
值的选项以显示为所选
<select ng-model="ctrl.country">
<option value="">select one</option>// default to show
<option ng-repeat="country in ctrl.countries" value="{{country.name}}">{{country.name}}</option>
</select>
相关文章:
- AngularJs列表ng单击以选择选项转换
- 如何使用AngularJs禁用ng选项中的选项
- 如何将ng选项的索引作为angularJs中的值传递给模型
- AngularJS ng选项在选择一个选项后删除了默认的空白值
- 当使用select作为标签时,如何使用ng选项禁用angularjs中的选项
- 角度引导选项卡ng如果错误
- 从服务器获取数据并在选择控件中使用ng选项无法显示选项
- ng选项-用vm替换$scope
- Angularjs-设置不带ng选项的select的默认值
- 角度去抖动(ng模型选项)不起作用
- ng选项-传递键而不是值
- Angular:如何使用ng选项进行四个单独的选择
- 选择框中带有关联的ng模型,选项中带有ng重复
- 使用ng选项,我如何筛选准确解释给定值的内容
- 角度Ng选项错误
- Angular.js通过对象关键点上的ng选项进行跟踪
- 选择/选项 ng-model 未绑定 ng-selected
- Angularjs 选择选项 ng 选择为分配值选择空白选项
- <选项 ng-repeat value={{object}}> 如何强制角度将对象推入模型
- 删除空白选项ng repeat和过滤后的ng选项