See this image for further understanding of my question:
I am trying to create dynamic checkbox buttons in rows and columns based on the value provided in object.
{"A":{"seats" : 10},"B":{"seats" : 8}}
At first you have to convert this object to array, like this:
$scope.array = [{ name: "A", seats: 10 }, { name: "B", seats: 8 }];
Then, to transform a number to array declare this below method:
$scope.getNumber = function (num) {
$scope.numbers = [];
for (var i = 1; i < num+1 ; i++) {
$scope.numbers.push(i);
}
return $scope.numbers;
}
Finally you should put ng-repeat
in your html.
<div ng-repeat="item in array">
<button type="button" ng-repeat="number in getNumber(item.seats)" ng-click="yourFunction()">
{{item.name}}{{number}}
</button>
</div>
if you have another question, ask me
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.