I've been searching for a solution to my problem both on StackOverflow and Google, but haven't been able to find one yet. So, here's my issue.
I have an array of DOM elements that I retrieve using the
@ViewChildren('labelSquare') public labelIcon: QueryList<HTMLSpanElement>;
decorator. In my HTML, I bind it as follows:
<span class="status-item" *ngFor="let status of statusList">
<div *ngIf="status.state !== 'Starting' &&
status.state !== 'Stopping' &&
status.state !== 'Synchronising' &&
status.state !== 'EmergencyStop'"
>
<div class="status">
<span #labelSquare class="status-square fas fa-square {{ status.state }}"></span>
<span class="status-name">{{ status.text }}</span>
</div>
</div>
</span>
This generates an array of 58 span elements, and now I want to add a border with a color that is 10% darker than its current background. To achieve this, I am using a map
:
if (this.labelIcon) {
this.labelIcon.map((icon: HTMLSpanElement) => {
const element = window.getComputedStyle(icon);
icon.setAttribute('style', `border: 1px solid ${ColorUtil.darkenBorderFromBackground(element.color)}`);
});
}
In my
ColorUtil.darkenBorderFromBackground()
function, I simply return return darken(${backgroundColor}, 10%)
. However, I encounter a TypeError: Failed to execute 'getComputedStyle' on 'Window': parameter 1 is not of type 'Element'
.
Can someone provide some assistance?