问题描述
1.html代码
<select ng-model='crystal.spacegroup' > <option ng-repeat='spaceGroup in spaceGroups' ng-selected='$index==0' value='{{$index+1}}'>{{spaceGroup}}</option> </select>
2.js代码
$scope.crystal={ lattice: [4, 4, 4, 90, 90, 90], spacegroup: 1, atoms: [{pos: [0, 0, 0],element: 1 }], symmetry: [['x', 'y', 'z'] ], centering: 'PRIMITIVE',}; $scope.spaceGroups= [ 'P 1', 'P -1','P 1 2 1', 'P 1 2_1 1', 'C 1 2 1']
3.问题描述:
1)代码大概是option显示的text来自spaceGroups数组,其value是其在spaceGroups数组中的下标。select的值和crystal.spacegroup属性绑定,已实现。 2)出现的问题是尽管我设置了ng-selected,select仍然没有默认选中值,我查看html的element是有selected='selected'属性的。 如图: ![图片描述][1]
问题解答
回答1:我用的你的代码试了一下,是有默认值的呀,传送门