1

I need to compare values inside ng-repeat. How to compare previous value with current value inside ng-repeat. I have an array, having values [2,3]. I want to compare array second value with first. How to do it?
Update: I am displaying current month and date and next seven days. Now if in next seven days there is new month, i mean as january after december, I need to include this month just before the dates of this month.
Ex:: Dec Tue 30, Wed 31, Jan Thu 1, Fri 2 ....

All code is here: Fiddle: http://jsfiddle.net/HB7LU/9763/

 <div class="row" style="text-align:center;background-color: #930d14; color: white; height: 55px;">
            <div class="col" style="border-right: solid 1px #820d13;">
                <p style="transform: rotate(270deg);margin-top: 8px;font-size: 10px;font-weight: 600;text-transform: uppercase;">
                    {{currentMonth}}</p>
            </div>
            <div class="col" style="border-right: solid 1px #820d13;" ng-repeat="days in totalDays.aryDates">
                <p style="font-size: 10px;font-weight: 500;">{{days}}</p>
                <p ng-if="totalDays.aryDates[$index-1] !== totalDays.aryDates[$index]" style="transform: rotate(270deg);margin-top: 8px;font-size: 10px;font-weight: 600;text-transform: uppercase;">
                    {{newMonth}}</p>
            </div>
Ved
  • 11,837
  • 5
  • 42
  • 60

2 Answers2

2

Angular.js loops have $index. You can use

  <div ng-repeat="item in items">
     <span ng-show="items[$index-1] == items[$index]"></span>
    </div>
erkan demir
  • 1,386
  • 4
  • 20
  • 38
1

In the ng-repeat you can refer to $index inside the loop. So access the array elements as array[$index] array [$index+1]

Peter Ashwell
  • 4,292
  • 2
  • 18
  • 22
  • It is working but my requirement is not fulfilled. I am updating my question. – Ved Jan 05 '15 at 09:57
  • Your question asked about comparing values in an ng-repeat. This answers that question. If you have another question then post another question. SO is for answering questions, not fulfilling 'your requirements' – Phil Degenhardt Jan 06 '15 at 21:43