I am having troubles with setting the default value of a select box in HTML using AngularJS.
Here's my scope variable in the controller:
$scope.sensorReadingsPerPage = 30;
and here's the selection box in the view that's using the controller:
<select id="itemsPerPage" name="itemsPerPage" class="panel panel-default" ng-model="sensorReadingsPerPage" ng-change="changeItemsPerPage()">
<option value="10">10</option>
<option value="20">20</option>
<option value="30">30</option>
<option value="40">40</option>
<option value="50">50</option>
<option value="100">100</option>
</select>
I want the option with '30' value to be preselected.
I've tried using this answer and this one, both of them referencing AngularJS documentation on select directive, but in these cases the options are being dinamically generated AND the scope consists in an object with several values in it. In my case, the options are static and there's just a variable on the scope.
How can I go around this? Is there a way to change the ng-init
and ng-options
to fit my case?