默认选择的值不能使用ng-init工作

时间:2014-04-21 13:47:46

标签: angularjs angularjs-ng-repeat angularjs-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)成为默认选定值。

1 个答案:

答案 0 :(得分:2)

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

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