Reputation: 68
Can we have one class being assigned to multiple expressions (basically boolean values) ?
Like for example I have class 'wrong-date-entered' and multiple expression that can be assigned to it such as $scope.futureDateEntered
, $scope.pastDateEntered
and $scope.invalidDateEntered
.
I know one way to do it as
<div ng-class="{class1: expressionData1, class1: expressionData2}">
</div>
But, I would be using this way too frequently and would want a shorter way out, maybe something like this:-
<div ng-class="{class1: expressionData1, expressionData2}"></div>
Is it possible ?
Upvotes: 0
Views: 33
Reputation: 3113
Combine both conditions in one like (expressionData1) || (expressionData2)
<div ng-class="{
class1: expressionData1 || expressionData2
}"></div>
You can use any number of conditions combined properly if you have to use one class for them, no need to write separatly.
Upvotes: 0
Reputation: 133453
You can use ||
operator
<div ng-class="{class1: expressionData1 || expressionData2}"></div>
Upvotes: 2