Directive in HTML
if:true|false={expression}if:true and if:false directives are no longer recommended. They may be deprecated and removed in the future. Use lwc:if, lwc:elseif, and lwc:else instead.if:true|false={expression} conditionally renders DOM elements in a template, calling the expression for each of if:true and if:false. In cases where you chain if:true and if:false directives, they are not as performant nor as lightweight as the lwc:if, lwc:elseif, and lwc:else directives. See Render DOM Elements Conditionally.expression can be a JavaScript identifier (for example, person) or dot notation that accesses a property from an object (person.firstName). The engine doesn’t allow computed expressions (person[2].name['John']). To compute the value of expression, use a getter in the JavaScript class.lwc:if|elseif={expression} and lwc:elseConditionally render DOM elements in alwc:if, lwc:elseif, and lwc:else supersede he if:true and if:false directives. Use the conditional directives on nested <template> tags, <div> tags or other <c-custom-cmp>.lwc:elseif and lwc:else must be immediately preceded by a sibling lwc:if or lwc:elseif.<template lwc:if={expression}></template>
<template lwc:else></template>lwc:if and lwc:elseif must evaluate an expression. However, lwc:else must not have an attribute value.<template lwc:if={expression}></template>
<template lwc:elseif={expression_elseif1}></template>
<template lwc:elseif={expression_elseif2}></template>
<template lwc:else></template>lwc:if and lwc:elseif supports simple dot notation.!condition, object?.property?.condition or sum % 2 === 1 aren't supported.NOTE The expressions and property getters are only accessed once per instance of an
lwc:if or lwc:elseif. In the above case, if expression is truthy, then none of the other property getters are accessed.lwc:elseif or lwc:else with text or another element. Whitespace is ignored between the tags when the whitespace is a sibling of the conditional directive. For example you can't have a <div> tag that comes after lwc:if and before lwc:else.<!-- Invalid -->
<template lwc:if={expression}></template>
This text node makes the pattern invalid
<div>This div tag makes the pattern invalid</div>
<template lwc:else></template>lwc:preserve-comments isn't enabled.expression is true.<template lwc:if={notCondition}></template>get notCondition() {
return !this.condition;
}NOTE
lwc:if, lwc:elseif, and lwc:else can't be applied to the same element and they cannot be combined with the if:true and if:false directives.
Oneplus Audio Days
0 Comments