Reputation: 35
I just updated the AngularJs version from AngularJS v1.4.8 to AngularJS v1.8.0 and I have a select which requires a default value. for some reason the ng-selected stop working. Can you please advise how to set the ng-selected on 1.8.0 please? (code uses an ng-model)
<input name="questionamount" class="form-control uservalue" type="number" min="0" ng-model="userInput1" ng-disabled="content.NotRelevant" ng-blur="setMainFieldAsTouched(); updateFormVisibility()" ng-change="update('userInput1',userInput1)" val-bubble>
<select name="questionperiod" class="form-control" ng-model="userInput2" ng-disabled="content.NotRelevant" ng-blur="setMainFieldAsTouched()" ng-change="update('userInput2',userInput2)" val-bubble>
<option value="">-- Select a period --</option>
<option value="48">Year</option>
<option value="24">6 Months</option>
<option value="12">Quarter</option>
<option value="4" ng-selected="true">Month</option>
<option value="5">Four Weekly</option>
<option value="2">2 Weeks</option>
<option value="1">Week</option>
</select>
<input name="questionvalue" class="form-control" type="number" min="0" readonly ng-required="content.Mandatory && !content.NotRelevant" max="{{content.TriggerLimit}}" ng-change="update('content.Value',content.Value)" ng-blur="updateFormVisibility()" ng-model="content.Value" val-bubble>
</div> ```
Thanks in advance,
Jordi
Upvotes: 0
Views: 373
Reputation: 950
From the docs:
Note: ngSelected does not interact with the select and ngModel directives, it only sets the selected attribute on the element. If you are using ngModel on the select, you should not use ngSelected on the options, as ngModel will set the select value and selected options.
Which would mean, set the value of userInput2 to your default value and do not use the ng-selected
attribute. See also this.
Upvotes: 1