I am looking to create functionality that involves storing the number of read messages in an array. I want to then reset this counter based on the difference between the length of the message array and the current counter value.
this.badgeCount = this.messages.length //5
The this.messages.length value is obtained from the service for each individual message.
Whenever the matMenu is closed, I need to reset the counter to zero and mark all messages as read.
menuClosed(){
this.badgeCount = 0;
this.messages.forEach((message: Message){
message.read = true;
})
}
The issue I am facing is that the this.messages.length always reflects the actual length, let's say 5. As a result, when a new message arrives, causing the length to increase to 6, the badgeCount also resets to 6 instead of 0. Is there a way to store the read messages in an array and calculate the count based on the total length of messages?