I'm facing a situation where my *ngFor
loops through incoming messages in this structure.
<ul id="messages">
<li *ngFor="let message of messages; let i = index">
<span id="actualMessage" [innerHTML]="isSystemMessage(message, i)"></span>
</li>
</ul>
Currently, I'm dealing with it using the isSystemMessage
method like this:
public isSystemMessage(message: string, i:number) {
return "<strong>" + i + ': ' + message + "</strong>"
}
While it works fine, I now want to limit the displayed messages to only the last 5 and delete any entries above them. But I'm unsure how to achieve this. Here's what I'm considering:
public isSystemMessage(message: string, i:number) {
if (i+1 == 5) {
//TODO: Remove all other entries from the webpage and display only the last 5.
}
return "<strong>" + i + ': ' + message + "</strong>" // otherwise, return the message
}
Is there a way to remove entries and update the UI accordingly?