0

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 ?

2 Answers 2

2

You can use || operator

 <div ng-class="{class1: expressionData1 || expressionData2}"></div> 
Sign up to request clarification or add additional context in comments.

1 Comment

Working perfectly fine. Thanks!
0

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.