2

See this image for further understanding of my question: Please visit 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}}
3
  • What have you tried? Please provide some information in your question (not a further comment). Commented Oct 14, 2018 at 8:16
  • do you need dynamic buttons? or checkbox? Commented Oct 14, 2018 at 10:07
  • @Farinaz the buttons should work as checkboxes so that on clicking the buttons i should get the list of buttons selected Commented Oct 14, 2018 at 10:20

1 Answer 1

5

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.