1.kod html
<select id="spgNumber" ng-model="crystal.spacegroup" >
<option ng-repeat="spaceGroup in spaceGroups" ng-selected="$index==0" value="{{$index+1}}">{{spaceGroup}}</option>
</select>
Kod 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.Penerangan masalah:
1)代码大概是option显示的text来自spaceGroups数组,其value是其在spaceGroups数组中的下标。select的值和crystal.spacegroup属性绑定,已实现。
2)出现的问题是尽管我设置了ng-selected,select仍然没有默认选中值,我查看html的element是有selected="selected"属性的。
如图:
![图片描述][1]
Saya mencubanya menggunakan kod anda, dan ia mempunyai nilai lalai, portal