I know in Angular you can dynamically add a class to the element but how do I change the value of a property? I want each button to be the next spotColour of the array. I feel like my example explains it well:
<button style="background-color: arrThemes[0]['spotColour']"></button>
<button style="background-color: arrThemes[1]['spotColour']"></button>
<button style="background-color: arrThemes[2]['spotColour']"></button>
arrThemes = [
{spotColour : 'rgb(238, 68, 136)', baseColour : 'rgb(80, 54, 78)'},
{spotColour : 'rgb(179, 165, 136)', baseColour : 'rgb(88, 67, 59)'},
{spotColour : 'rgb(87, 167, 82)', baseColour : 'rgb(47, 68, 46)'},
];
Try something like this expression with
<button style="{{ 'background-color: ' + arrThemes[0]['spotColour'] }}"></button>
or in more civil way using NgStyle
<button [ngStyle]="{'background-color': arrThemes[0]['spotColour']}"></button>
use ngStyle tag to dynamically add styles
<button *ngFor="let item of arrThemes " [ngStyle]="{'background-color': item.spotColour }"></button>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With