1

Can we write ternary operator in DIV tag on LWC as below.

<div class = if:true= {showleftDiv} ? slds-size_4-of-6 : slds-size_4-of-6 >
1

1 Answer 1

8

You need to move all the expressions into js. This is done on purpose to make the code more testable as mentioned in documentation

Example

Html

<div class={divClass}></div>

JS

get divClass() {
   return this.showleftDiv ? 'slds-size_4-of-6' : 'slds-size_6-of-6';
}

Not the answer you're looking for? Browse other questions tagged .