Is there a way to prevent the class for each notification from changing when I click on something? I want to create a read more/read less functionality in Angular for notifications, and have all notifications expand when the button is clicked.
<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>",
}
];
I am using this dummy data for testing, as I will be receiving similar data from the server.
I am new to development, so please bear with me. I have used the method below and it seems to work fine. Is this the best practice?
<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>