Quick Fix:
To efficiently manage the data, store objects in an array:
private data = [
{full_name: 'Jenny', phone_number: '8458 7098', email: '<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="a8edd0c9c5d8c4cde8d1c9c0c7c786cbc7c5">[email protected]</a>', dob: '14/11/1994', status: 'Served', appointment_type: 'Online', queue_num: '1', gender: 'Female', race: 'Malay', height: '169', weight: '55'},
{full_name: 'Howard', phone_number: '8845 5888', email: '', dob: '09/11/1987', status: 'Served', appointment_type: 'Online', queue_num: '2', gender: 'Male', race: 'Chinese', height: '175', weight: '75'},
{full_name: 'Kelly', phone_number: '9145 5843', email: '<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="16536e777b667a73566f777e79793875797957">[email protected]</a>', dob: '25/02/1960', status: 'Current', appointment_type: 'Online', queue_num: '3', gender: 'Male', race: 'Chinese', height: '172', weight: '63'},
{full_name: 'David Yang', phone_number: '9145 5843', email: '<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d99ca1b8b4a9b5bc99a0b8b1b6b6f7bab6b4">[email protected]</a>', dob: '25/02/1960', status: 'Next', appointment_type: 'Online', queue_num: '4', gender: 'Male', race: 'Chinese', height: '172', weight: '63'},
{full_name: 'Jun Hao', phone_number: '9145 5843', email: '<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="6f2a170e021f030a2f160e070000410c0002">[email protected]</a>', dob: '25/02/1960', status: 'Next', appointment_type: 'Online', queue_num: '5', gender: 'Male', race: 'Chinese', height: '172', weight: '63'},
{full_name: 'Xia Long', phone_number: '9145 5843', email: '<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="397c41585449555c794058515656175a5654">[email protected]</a>', dob: '25/02/1960', status: 'Next', appointment_type: 'Online', queue_num: '6', gender: 'Male', race: 'Chinese', height: '172', weight: '63'}
];
Create a simple filter method for entries, focusing on their status:
getServedCount(): number {
return this.data.filter(entry => entry.status === 'Served').length;
}
Incorporate the method call into the template to retrieve the count:
COUNT: {{ getServedCount() }}
Streamlined / Enhanced Solution:
Template:
<hello name="{{ name }}"></hello>
<p>
Start editing and witness the magic unfold :)
</p>
COUNT: {{ servedCount }}
TypeScript:
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: [ './app.component.css' ]
})
export class AppComponent implements OnInit {
// DATA may come from various sources like services or cookies. For now, we initialize it with dummy data in a private variable.
private data = [
{full_name: 'Jenny', phone_number: '8458 7098', email: '<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="f7b28f969a879b92b78e969f9898d994989a">[email protected]</a>', dob: '14/11/1994', status: 'Served', appointment_type: 'Online', queue_num: '1', gender: 'Female', race: 'Malay', height: '169', weight: '55'},
{full_name: 'Howard', phone_number: '8845 5888', email: '', dob: '09/11/1987', status: 'Served', appointment_type: 'Online', queue_num: '2', gender: 'Male', race: 'Chinese', height: '175', weight: '75'},
{full_name: 'Kelly', phone_number: '9145 5843', email: '<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="5e1b263f332e323b1e273f363131703d3133">[email protected]</a>', dob: '25/02/1960', status: 'Current', appointment_type: 'Online', queue_num: '3', gender: 'Male', race: 'Chinese', height: '172', weight: '63'},
{full_name: 'David Yang', phone_number: '9145 5843', email: '<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="36734e575b465a53764f575e59591855595b">[email protected]</a>', dob: '25/02/1960', status: 'Next', appointment_type: 'Online', queue_num: '4', gender: 'Male', race: 'Chinese', height: '172', weight: '63'},
{full_name: 'Jun Hao', phone_number: '9145 5843', email: '<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="703508111d001c15300911181f1f5e131f1d">[email protected]</a>', dob: '25/02/1960', status: 'Next', appointment_type: 'Online', queue_num: '5', gender: 'Male', race: 'Chinese', height: '172', weight: '63'},
{full_name: 'Xia Long', phone_number: '9145 5843', email: '<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="2d68554c405d41486d544c454242034e4240">[email protected]</a>', dob: '25/02/1960', status: 'Next', appointment_type: 'Online', queue_num: '6', gender: 'Male', race: 'Chinese', height: '172', weight: '63'}
];
// Public variable to be accessed in the template
public servedCount = 0;
ngOnInit(): void {
// Triggers the "getServedCount" method once upon initialization.
this.servedCount = this.getServedCount(this.data);
}
private getServedCount(data): number {
return data.filter(entry => entry.status === 'Served').length;
}
}
For additional reference, click on the following link. :-)