I have a component that generates multiple buttons next to each other, each with a specific style. Additionally, each button is randomly assigned a different color based on its class.
The issue I am facing is that when I include this component in one of my other component HTML files, it displays correctly. However, when I try to add it to another component, the design appears completely off.
It seems like the CSS styles are not being applied to the new components for some reason...
Even though it's the same code as it's an imported component, I'm puzzled by why it doesn't work...
Below is my code:
--> status-bar.component.html
<div *ngFor="let button of [1,2,3,4,5,6,7,8,9,10]; index as i">
<button id={{i}} [ngStyle]="getClassrandom(i)"></button>
</div>
--> status-bar.component.ts
import { Component, Input, OnInit, Output, EventEmitter} from '@angular/core';
@Component({
selector: 'status-bar',
templateUrl: './status-bar.component.html',
styleUrls: ['./status-bar.component.scss']
})
export class StatusBarComponent implements OnInit {
getClassrandom(i: number): any {
const classesArray = [
'status__button status__button--red',
'status__button status__button--yellow',
'status__button status__button--green'];
const element = document.getElementById(i.toString());
element.className = classesArray[Math.floor(Math.random() * 3)];
}
constructor() {
}
ngOnInit(): void {
}
}
---> status-bar.component.scss
.status__button {
float:left;
height: 80px;
width: 25px;
border-radius: 10px;
border: 1px solid rgb(255, 255, 255);
text-align: center;
-webkit-appearance: none;
-moz-appearance: none;
margin: 0;
box-shadow: 0px 3px 5px 0px rgba(0, 0, 0, 0.2);
cursor: pointer;
}
.status__button--green {
background: limegreen;
box-shadow: 0px 5px 7px 0px rgba(0, 0, 0, 0.2);
opacity: 0.5;
&:hover {
opacity: 1;
}
}
.status__button--yellow {
background: yellow;
box-shadow: 0px 5px 7px 0px rgba(0, 0, 0, 0.2);
opacity: 0.5;
&:hover {
opacity: 1;
}
}
.status__button--red {
background: red;
box-shadow: 0px 5px 7px 0px rgba(0, 0, 0, 0.2);
opacity: 0.5;
&:hover {
opacity: 1;
}
}
I am using this component in other components like test-bar.component.html or status-bar.component.html
The main component is status.component, which imports all the others along with the status modules.
If anyone has insight into what might be causing this issue, please share your thoughts.