Okay so I'm currently trying to set the color value of an <input type="color">
via [value]
using a function inside the TS of the component like this:
HTML
<input type="color" [value]="getRandomColor()" title="Choose your color">
TS
export class FiltersComponentComponent implements OnInit {
constructor() { }
getRandomColor() {
var letters = '0123456789ABCDEF';
var color = '#';
for (var i = 0; i < 6; i++) {
color += letters[Math.floor(Math.random() * 16)];
}
return color;
}
ngOnInit(): void {
}
}
The thing is that the random color is setted, but its getting setted in a never ending loop, so every frame the color is getting refreshed. I've tried to replicate the error in a StackBlitz but there it simply works! Here it is. This is the error the console gives me on my project :
core.js:5980 ERROR Error: NG0100: ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked. Previous value: '#60B9D1'. Current value: '#84DFC7'.
Any idea?