Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Default option in select

Tags:

html

angularjs

I have this very simple select element:

<label>Items per page</label>
    <select class="form-control input-sm w25" ng-model="itemsPerPage">
        <option value="5">5</option>
        <option value="10">10</option>
        <option value="25">25</option>
        <option value="50">50</option>
    </select>

with controller:

 $scope.itemsPerPage = 5; // default value

But the default value is a blank option and the default value attempt doesn't do anything.

How do I make the value 5 the default?


1 Answers

Angular is probably converting that value to a string, so do:

$scope.itemsPerPage = "5";
like image 170
tymeJV Avatar answered Jan 23 '26 13:01

tymeJV



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!