0

I am using bootstrap and would like to ng-repeat through an array but i need to get the 2 values each loop. For the example i wish b.name to be booking[0] and the other b.name to be booking[1]. i am currently adding each row and then adding the value.

<div class="row" ng-repeat="b in booking">
    <div class="col-sm-6">
        <label><input icheck type="checkbox" ng-model="basicIntake.email_subscription">
            {{b.name}}
        </label>
    </div>
    <div class="col-sm-6">
        <label><input icheck type="checkbox" ng-model="basicIntake.email_subscription">
            {{b.name}}
        </label>
    </div>
</div>
2
  • Do you want even and odd indexes differentation? Commented Apr 11, 2017 at 8:42
  • 1
    If it is to create a row with 2 col-sm-6 each time it is usesless, just use one row and loop for col-sm-6 as much as you want Commented Apr 11, 2017 at 8:46

2 Answers 2

3

Here's what you can do. You put ng-if="$even" so for odd numbers, it won't render it. But, you can render next odd number in same row using {{booking[$index+1].name}}.

Something like this:

<div class="row" ng-repeat="b in booking" ng-if="$even">
    <div class="col-sm-6">
        <label><input icheck type="checkbox" ng-model="basicIntake.email_subscription">
            {{b.name}}
        </label>
    </div>
    <div class="col-sm-6">
        <label><input icheck type="checkbox" ng-model="basicIntake.email_subscription">
            {{booking[$index+1].name}}
        </label>
    </div>
</div>

Or, you can loop through col-sm-6 instead of its parent.

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

1 Comment

Only one who unterstood it was about bootstrap. I like your solution though I would just loop over col-sm-6
1

You can try

<div class="row" >
    <div class="col-sm-6" ng-repeat="b in booking | limitTo:2">
        <label><input icheck type="checkbox" ng-model="basicIntake.email_subscription">
            {{b.name}}
        </label>
    </div>
    <div class="col-sm-6" ng-repeat="b in booking | limitTo:2:2">
        <label><input icheck type="checkbox" ng-model="basicIntake.email_subscription">
            {{b.name}}
        </label>
    </div>
</div>

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.