quma
quma

Reputation: 5733

AngularJS style set background

I have the following Javascript objects:

My Objects look like this

There are two properties of this objects: pesonalColor and personRoleColor I have a flag called vm.colorSwitch with which I will switch the color of the span below. With personalColor it works fine but I don't know how to bring in personRoleColor to switch between the colors.

Thanks a lot for your help!

<span ng-repeat="myObject in myObjects" style="width:{{myObject.percentage}}%; background:{{myObject.personalColor}}" class="progress-bar" />

Upvotes: 2

Views: 34

Answers (1)

Anid Monsur
Anid Monsur

Reputation: 4538

ngStyle allows programatic use of the style attribute.

<span ng-style="{
    background: vm.colorSwitch ? myObject.personalColor : myObject.personRoleColor, 
    width: myObject.percentage + '%'
}" ...></span>

Upvotes: 2

Related Questions