1
votes

My question is very simple, but I can't get it. I have a select to order elements in AngularJS with custom options. I just need to get one option selected when the page loads.

Here's my code:

<select ng-model="sortBy">
    <option value='priceOrder'>Price order</option>
    <option value='price'>Price - +</option>
    <option value='-price'>Price + -</option>
    <option value='weight'>Weight + -</option>
    <option value='-weight'>Weight - +</option>
</select>

The values comes from a Json in my controller.js, and I ask for order in:

<li ng-repeat="item in filteredGenere | filter:query | orderBy:sortBy" >.
   {{item.brand}} {{item.name}}
</li>
1

1 Answers

2
votes

If you want the select box has one option selected when page loaded, you need to initialize $scope.sortBy in your controller like

$scope.sortBy = 'priceOrder';

Check this demo