Angularjs 选择通过ng repeat和ng选项未生成的下拉列表
下面的两个下拉列表不会生成一个年份数组。我还需要从最早到最晚对年份进行排序,但orderBy筛选器不起作用Angularjs 选择通过ng repeat和ng选项未生成的下拉列表,angularjs,sorting,angularjs-orderby,Angularjs,Sorting,Angularjs Orderby,下面的两个下拉列表不会生成一个年份数组。我还需要从最早到最晚对年份进行排序,但orderBy筛选器不起作用 <select title="- Select a period -" class="period " id="reportingPeriods"> <option ng-repeat="reportingPeriod for reportingPeriod in reportingPeriods">{{reportingPeriod}}</
<select title="- Select a period -" class="period " id="reportingPeriods">
<option ng-repeat="reportingPeriod for reportingPeriod in reportingPeriods">{{reportingPeriod}}</option>
</select>
<br />
<select title="- Select a period -" class="period selectpicker" id=""
ng-options="reportingPeriod for reportingPeriod in reportingPeriods | orderBy: '-reportingPeriod' ">
</select>
这是我的您对ng选项和选择选项中的ng repeat使用了错误的语法。固定在这里- 您还需要将ng模型分配给select以使其工作(如@AvijitGupta在上面的评论中所述)
{{reportingPeriod}
ng选项
也需要ng型号
!您正在清除控制台,该控制台正在为您的plunkr隐藏错误。。你知道为什么订货人根本不工作吗?哦,我没注意到,我来看看。感谢您提供的信息。表达式正在查找数值上的reportingPeriod
属性。我已经修正了plunkr和上面的答案来反映这一点。
(function(angular) {
'use strict';
angular.module('ngrepeatSelect', [])
.controller('ExampleController', ['$scope', function($scope) {
console.clear();
$scope.data = {
repeatSelect: null,
availableOptions: [
{id: '1', name: 'Option A'},
{id: '2', name: 'Option B'},
{id: '3', name: 'Option C'}
],
};
$scope.reportingPeriods = [1999, 2011, 2000, 1988, 1995, 2014];
}]);
})(window.angular);
<select ng-model="period" title="- Select a period -" class="period " id="reportingPeriods">
<option ng-repeat="reportingPeriod in reportingPeriods">{{reportingPeriod}}</option>
</select>
<br />
<select ng-model="preiod" title="- Select a period -" class="period selectpicker" id=""
ng-options="reportingPeriod for reportingPeriod in reportingPeriods | orderBy: '-' ">
</select>