I am working on an Angular web app that includes an HTML table. The data for this table is retrieved from a database via a service and displayed as text.
One of the columns in the table represents a Status, which I want to visually represent as a colored circle instead of plain text. For example, if the cell value is "green", it should display a green circle.
Below is my current approach:
CSS (Component Styles snippet):
:host ::ng-deep td.circle {
text-align: center;
font-size: 0;
background-color: RED; <--- need to pass param here
}
The column styling is defined as follows:
.circle {
border-radius: 50%;
height: 24px;
width: 24px;
}
HTML:
<app-table [attrs]="serviceapi" [monthSelected]="monthSelected" ></app-table>
Corresponding TypeScript code for the table: In the constructor:
this.data = {
headers: [],
rows: []
};
ngOnInit() {
this.tableMetricsService.getTableMetrics(
JSON.parse(this.attrs).api,
this.monthSelected
).subscribe(response => {
this.data = response;
}
);
}
Does anyone have suggestions for translating cell values into corresponding CSS background colors?
Thanks in advance,
Oleg.