2014-04-21 75 views
1

只需在Angular中设置一个默认的选定值,但到目前为止我没有运气。使用ng-init默认选定的值不起作用

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> 

如何使值= 0(所有)的默认选定值。

回答

2

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

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