Skip to content Skip to sidebar Skip to footer

How To Set A Preselected Option As Default In A Select Field Using Angularjs

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 her

Solution 1:

Try setting $scope.sensorReadingsPerPage = "30" in your controller.

Note: It should be a string.

Solution 2:

Have you tried using ng-options instead of creating separate option elements?

<select id="itemsPerPage" name="itemsPerPage" class="panel panel-default" ng-options="item in items track by $index" ng-model="sensorReadingsPerPage" ng-change="changeItemsPerPage()">

And in your controller

$scope.items = [10, 20, 30, 40, 50, 100];
$scope.sensorReadingsPerPage = $scope.items[2];

Post a Comment for "How To Set A Preselected Option As Default In A Select Field Using Angularjs"