我使用这个Jquery来选择第n个孩子
<select class="perf-select">
<option selected>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
</select>
jquery的
jQuery('.perf-select>option:eq(2)').prop('selected', true);
我如何在angularjs ng-option
中实现这一目标<select class="perf-select" ng-model="viewProfileCtrl.graphsForm.institution"
ng-options="inst.institution.institution_id as inst.institution.name for inst in viewProfileCtrl.perfiosAnalysisData.institutions"
ng-change="viewProfileCtrl.setGraphInsti(viewProfileCtrl.graphsForm.institution)">
<option value="" selected>Select a Bank </option>
</select>
答案 0 :(得分:0)
请使用 selectedOption 有关详情https://docs.angularjs.org/api/ng/directive/select,请转到使用带有ngOptions的select并设置默认值部分。我希望这能帮到您。
答案 1 :(得分:0)
到目前为止,最好的办法是array.indexOf
ng-options="countries.indexOf(country) as country.name for country in countries"
答案 2 :(得分:0)
如果你想在下拉列表中将第n个孩子设置为默认选项,你必须根据控制器中的第n个孩子设置你的ng模型,如 -
$ scope.graphsForm.institution = 3;
这里“graphsForm.institution”是你的下拉模型,“3”是你想要设置为默认的第n个孩子的关键(就像你的例子“institution_id”)。
您可以查看此内容以便更好地理解 -
redirect