2017-03-03 39 views
0

我陷入了尴尬的问题,我需要改变视情况而定角JS:使用NG风格指令的

这里的文字颜色的单一属性的几个条件是我在做什么。

ng-style="{'color': 
order.order_status_id === '2' ? 'red' : 
order.order_status_id === '3' ? 'green' : 
order.order_status_id === '5' ? 'blue' : 
''}" 

我使用的方式是一种解决方法。该场景是否有实际的angular解决方案?

回答

2

在我看来,你可以做这样的事情,这是完全一样,但更漂亮。

在你的控制器定义取消对象color

$scope.color = { 
    2: 'red', 
    3: 'green', 
    5: 'blue' 
}; 

然后你ngStyle可能是

ng-style="{'color': color[order.order_status_id]}" 

这一切;)