Trying to generate randomly html color codes but not working. So, How to generate it in the for loop. I have tried in google and stackoverflow, but not able to find out the solution. If anyone knows please help to find the solution.
Example totalColor should be like ['#CD5C5C','#F08080','#FA8072','#E9967A',.....upto 10]
app.component.ts:
getrandomcolor(length) {
let letters = '0123456789ABCDEF';
let color = '#';
for (let i = 0; i < length; i++) {
color += letters[Math.floor(Math.random() * 16)];
this.totalColor.push(color);
}
console.log(this.totalColor);
}
Demo : https://stackblitz.com/edit/angular-ivy-kvdhev?file=src%2Fapp%2Fapp.component.ts