我的totalcount为585.需要动态地根据totalcount选项值(totalcount / 10)。像1,2,3,4,5,6。先前:
<div class="form-inline pull-right">
<div class="form-group">
<label>Entries</label>
<select ng-model="$ctrl.entries" class="input-sm border-radius-none form-control">
<option ng-value="10">10</option>
<option ng-value="20">20</option>
<option ng-value="30">30</option>
<option ng-value="40">40</option>
<option ng-value="50">50</option>
</select>
</div>
<span>
</span>
</div>
答案 0 :(得分:0)
您应该使用ngOptions
指令填充选项
(function(angular) {
'use strict';
angular.module('myApp', [])
.controller('Controller', ['$scope', function($scope) {
this.entries = 1;
this.totalcount = 58;
this.populate = function() {
var arr = [];
for (var i = 0; i < this.totalcount / 10; i++)
arr.push(i + 1);
return arr;
}
}]);
})(window.angular);
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.7/angular.min.js"></script>
<div ng-app="myApp">
<div ng-controller="Controller as $ctrl">
<label>Total Count</label>
<input type="number" ng-model="$ctrl.totalcount">
<br>
<label>Entries</label>
<select ng-model="$ctrl.entries" ng-options="o as o for o in $ctrl.populate()">
</select>
<br>
{{$ctrl.populate()}}
</div>
</div>
答案 1 :(得分:0)
您需要创建一个数字数组。使用以下代码:
arrOfNums = [];
let arrLength = $scope.totalCount%10 + 1;
for(let i = 1; i < arrLength; i++) {
arrOfNums.push(i*10);
}
现在你有了数组。在模板中使用此数组。 希望它会有所帮助
答案 2 :(得分:0)
如果您不想在控制器中创建额外功能,也可以执行此类操作
ng-options=" n as n for n in [10, 20, 30, 40, 50, 60]"