【问题标题】:Default selected value not working using ng-init使用 ng-init 时默认选择的值不起作用
【发布时间】:2014-04-21 13:47:45
【问题描述】:

只是尝试在 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) 成为默认选择值。

【问题讨论】:

    标签: angularjs angularjs-ng-repeat angularjs-ng-init


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-01-07
      • 2019-02-21
      • 1970-01-01
      • 1970-01-01
      • 2014-02-22
      相关资源
      最近更新 更多