使用ng init时默认选择的值不起作用



只是想在Angular中创建一个默认的选定值,但到目前为止我运气不佳。

编译前的HTML:

<select ng-options="select.Value as select.Name for select in ruleSelect" ng-model="rule.MatchLogic" ng-init="rule.MatchLogic = 0" ></select>

HTML浏览器源代码:

<select ng-options="select.Value as select.Name for select in ruleSelect" ng-model="rule.MatchLogic" class="ng-pristine ng-valid">
<option value="?" selected="selected"></option>
<option value="0">All</option>
<option value="1">At Least</option>
<option value="2">At Most</option>
</select>

如何使value=0(All)成为默认的选定值。

您所需要做的就是将ng-modelrule.MatchLogic设置为等于选项中的相应值。您使用的选项是ruleSelect

例如,在控制器中设置rule.MatchLogic = ruleSelect[someSelector].Value;

最新更新