如何使用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 關注
- 1323 瀏覽
添加回答
舉報
0/150
提交
取消