I would like to apply background-colorwith ng-styleconditionally when the color value can be updated with$scope .
Here are my scope variables:
$scope.someone = { id: '1', name: 'John', color: '#42a1cd' };
$scope.mainId = 1;
In fact, I do not use any conditions for applying the background color, this is done with:
<div ng-style="{'background-color': someone.color}">
{{someone.name}}
</div>
The idea here is to apply this background color only whensomeone.id == mainId . I tried several solutions, but it seems this is not the correct syntax:
ng-style="{{someone.id == mainId}} ? ('background-color': {{someone.color}}) : null"ng-style="{ ('background-color': someone.color) : someone.id == mainId }"
Does anyone have any idea how I can achieve this?
source
share