I am using ngStyle property binding with my HTML element to bind dynamic style in my Angular component like below:
example.component.ts
.spinnerStyle = {
'background': this.color,
'background': `-moz-linear-gradient(left, ${this.color} 10%, rgba(255,128,0, 0) 42%)`,
'background': `-webkit-linear-gradient(left, ${this.color} 10%, rgba(255,128,0, 0) 42%)`,
'background': `-o-linear-gradient(left, ${this.color} 10%, rgba(255,128,0, 0) 42%)`,
'background': `-ms-linear-gradient(left, ${this.color} 10%, rgba(255,128,0, 0) 42%)`,
'background': `linear-gradient(to right, ${this.color} 10%, rgba(255,128,0, 0) 42%)`
}
example.component.html
<div class="loader" [ngStyle]="spinnerStyle">Loading...</div>
As we can see my typescript file is having an object representing my CSS style. It is a valid CSS, but an invalid typescript object as it is having duplicate identifiers. My compilation is failing due to this. What should be the alternate approach?