2014-04-21 77 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;