How do I make sure that the class for each notification does not change when I press the ..., I want to implement read more read less in angular for given notifications, and with this, if I press the button all the notifications get opened.
<div class="notificationList" *ngFor="let a of alertsList">
<div [ngClass]="{'showLess': more}" [innerHTML]="a.Message"></div>
<a class="readMore" (click)="more==!more">...</a>
</div>
public alertsList: any = [
{
"Message": "<p>hi hello</p><p>dsaddddsdad ad s sdaf asf sf sd sd fsa ff sdf af s fsa f sadf sa faf sadf a a fa</p>",
},
{
"Message": "<p>hi hello</p><p>dsaddadsaddd ad s sdaf asf sf sd sd fsa ff sdf af s fsa f sadf sa faf sadf a a fa</p>",
},
{
"Message": "<p>hi hello</p><p>dsadddd ad gfgdgfds sdaf asf sf sd sd fsa ff sdf af s fsa f sadf sa faf sadf a a fa</p>",
},
{
"Message": "<p>hi hello</p><p>dsadddd ad s sdadfgfdgf asf sf sd sd fsa ff sdf af s fsa f sadf sa faf sadf a a fa</p>",
}
];
Using this dummy data to check, as I will be receiving data from the server in this manner only
I am a new developer so please bare with me, i used this method below and it worked can you please tell me if its the best practice or not?
<div class="notificationList" *ngFor="let a of alertsList; index as i">
<div [ngClass]="{'showMore': more[i], 'showLess': !more[i]}" [innerHTML]=" a.Message">
</div>
<a class="readMore" (click)="more[i]=!more[i]">...</a>
</div>