ng-style
有条件的(
)用于检查某些字符串并给出特定样式的运算符。这是它的样子:
<span ng-style="product.interaction=='CAUTION' ? {color:'red'} : ''">
{{product.interaction}}
</span>
其他的
只需扩展else子句
<span ng-style="product.interaction=='CAUTION' ? {color:'red'} : {color:'white'}">
{{product.interaction}}
</span>
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
$scope.product = {};
$scope.product.interaction = "CAUTION";
$scope.product.interaction2 = "ANYTHING";
});
<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script>
<body>
<div ng-app="myApp" ng-controller="myCtrl">
<div class="alcohol">
<span ng-style="product.interaction2=='CAUTION' ? {color:'red'} : {color:'white'}">
{{product.interaction2}}
</span>
<span ng-style="product.interaction=='CAUTION' ? {color:'red'} : {color:'white'}">
{{product.interaction}}
</span>
</div>
</div>
</body>
</html>