答案 0 :(得分:2)
CONTROLLER
var app = angular.module('myapp',[]);
app.controller('ctrlParent',function($scope){
$scope.count =3;
$scope.getNumber = function(num) {
return new Array(num);
}
});
HTML
<li ng-repeat="i in getNumber(myNumber) track by $index"><span>{{$index+1}}</span></li>
<强> JSFIDDLE 强>
答案 1 :(得分:0)
$scope.number = 5;
$scope.getNumber = function(num) {
return new Array(num);
}
<ul>
<li ng-repeat="i in getNumber(number)"><span>{{$index+1}}</span></li>
</ul>
答案 2 :(得分:0)
不确定你的意思。但根据我的观点,你有两个问题: 1.在json文件中读取计数 2.在视图中显示n span。
要读取json文件,您可以创建一个服务来获取它。请遵循此Reading data from JSON file in Angularjs
显示显示那些范围,使用ng-repeat: 你好,世界 count是ur控制器中的$ scope变量。
希望这个帮助
答案 3 :(得分:0)
你可以这样做。
var app = angular.module("sampleApp", []);
app.controller("sampleController", ["$scope",
function($scope) {
$scope.pro = [{
product: "chicken",
rating: 3
}, {
product: "fish",
rating: 1
}, {
product: "pizza",
rating: 4
}];
$scope.repeat = function(rating) {
return new Array(rating);
}
}
]);
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.8/angular.min.js"></script>
<div ng-app="sampleApp">
<div ng-controller="sampleController">
<div ng-repeat="array in pro">
<div>{{array.product}}
<span ng-repeat="number in repeat(array.rating) track by $index" ng-init="">*</span>
</div>
</div>
</body>
</div>
</div>