如何使用ng-选项设置SELECT元素的默认值我在这里看到了角选择指令的文档:http:/docs.angularjs.org/api/ng.指令:选择..我不知道如何设置默认值。这是令人困惑的:为数组中的值选择为标签这是一个对象:{
"type": "select",
"name": "Service",
"value": "Service 3",
"values": [ "Service 1", "Service 2", "Service 3", "Service 4"] }html(工作):<select><option ng-repeat="value in prop.values">{{value}}</option></select>然后,我尝试在SELECT元素中添加一个ng选项属性来设置prop.value作为默认选项(不起作用)。ng-options="(prop.value) for v in prop.values"我做错什么了?
3 回答
开心每一天1111
TA贡献1836条经验 获得超13个赞
script.js
function MyCntrl($scope) { $scope.colors = [ {name:'black', shade:'dark'}, {name:'white', shade:'light'}, {name:'red', shade:'dark'}, {name:'blue', shade:'dark'}, {name:'yellow', shade:'light'} ]; $scope.color = $scope.colors[2]; // Default the color to red}
<select ng-model="color" ng-options="c.name for c in colors"></select>
<select>
ng-options
*
- 3 回答
- 0 关注
- 1289 浏览
添加回答
举报
0/150
提交
取消