Attempting to compare 2 entries in an *ngFor loop. The code should compare the value at the current object to a value at the previous object.
<ng-container *ngFor="let item of s_1.comments[0]; index as b">
<article class="message is-small is-size-6" >
<div class="header {{item.type}}">
{{item.type | stringyfy:'_' | titlecase}} <div class="text">{{item.mood}}</div>
</div>
<div class="body" *ngFor="let comment of item.comments">
{{comment.text}} </div>
</article>
<article class="message " *ngIf="b >= 1 && item.rating > item[b-1].rating;">
<div class="message-header">
</div>
<div class="message-body" >
Mood All Year
</div>
</article>
</ng-container>
Using *ngIf
to display data conditionally based on the result when the Rating is higher than the previous entry's Rating.
An error arises because of subtracting 1 from b.
<article class="message " *ngIf="b >= 1 && item.rating > item[b-1].rating;">
<div class="message-header">
</div>
<div class="message-body" >
Mood All Year
</div>
</article>
What is the issue here?
An error shows up in the console stating that item_r86[(b_r87 - 1)]
is undefined, likely due to the -1 subtraction.