选择Angularjs中的选定选项

时间:2015-06-03 07:00:21

标签: angularjs select

我的问题非常简单,但我无法理解。我有一个选择在AngularJS中使用自定义选项订购元素。我只需要在页面加载时选择一个选项。

这是我的代码:

<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>

值来自我controller.js中的Json,我要求订购:

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

1 个答案:

答案 0 :(得分:2)

如果您希望选择框在加载页面时选择了一个选项,则需要在控制器中初始化$scope.sortBy,如

$scope.sortBy = 'priceOrder';

选中此demo

相关问题