user2128 user2128 - 6 months ago 21
AngularJS Question

using $index to compare values returned by ng-repeat

I have an array object of size 2. I am doing ng-repeat on the array object and displaying the values. But now I want to also compare the values inside the object. Can i use $index for that ?

I tried using $index, $index-1 but it is not working. Infact it won't display any value at all.

div.timeline-block(ng-repeat="(key,value) in vm.alertHistoryData | groupBy: 'historyDateWithoutTime' | toArray:true | orderBy: 'historyDateWithoutTime':true " )
h2.timeline-block-header
| {{ value[0].historyDateWithoutTime | date: "mediumDate" }}
ul.timeline-entry-list
//- to make the array of data render in reverse order we add "true" to orderBy filter
li.timeline-entry-list-item(ng-repeat= "history in value | orderBy: 'alert-modified-date':true")
h3.list-item-time
| {{ history["alert-modified-date"] | date:"mediumTime"}}
div.list-item-content
div.label-block.label-block-horz
| State
div.label-block-value
| {{ history.state[$index] | alertState }}
hr.hr-default.hr-spacer-sm
div.label-block-value
| {{ history[$index-1].state }}
div.label-block.label-block-horz
| Priority:
div.label-block-value
span.label-priority(ng-class="'priority-{{history.priority}}'")
| {{ history.priority}}


Is it because I am using filter also? Please help

Answer

history is a item in value.

Change:

history[$index-1].state

To:

value[$index-1].state