Question

Simply trying to make a default selected value in Angular but thus far I am having no luck.

HTML Before Compile:

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

HTML In Browser Source:

<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>

How do I make value=0 (All) the default selected value.

Was it helpful?

Solution

All you need to do is set your ng-model value rule.MatchLogic to equal the corresponding value in the options. The options you use are ruleSelect.

So for example, set rule.MatchLogic = ruleSelect[someSelector].Value; inside your controller.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top