If:true is not working properly in LWC, Can anyone please explain?

476    Asked by CarolBower in Salesforce , Asked on Apr 22, 2021


Answered by Clare Matthews

The reason why if:true={value} equals false is because 0 value is falsy. if:true directive expects boolean context, thus making type coercion. I'd recommend you to use getters. In your case, it can be looked like (if you expect the value property of number type):

@track value = 0; get hasValue() { return typeof value === 'number' && isFinite(value); }

Hope this wil resolve your issue.



Your Answer

Interviews

Parent Categories