I have an auraif
when I tried to use the condition And (&&
) it points error:
<aura:if isTrue="{!v.value == 'test' && v.recTypeName == 'testing'}">
</aura:if>
Try to use the and
expression function, as in:
<aura:if isTrue="{! and(equals(v.value, 'test'), equals(v.recTypeName, 'testing')) }">
https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/expr_functions.htm
equal
function as well. If it still throws you an error, it is likely a problem outside this expression.
Commented
Jun 14, 2019 at 15:49
Assuming that you are trying to use &&
and getting error, then that's expected. Using &&
is not allowed in components. You will need to use &&
in that case.
However, it is recommended that you use and(condition)
. This is from the documentation:
&&
This syntax is awkward in markup so we recommend using theand
function instead.
You can do your calculations in a javascript controller and write the result to an aura attribute
Component Markup
<aura:component>
<!-- Attributes -->
<aura:attribute name="value" type="String"/>
<aura:attribute name="recTypeName" type="String"/>
<aura:attribute name="testValue" type="Boolean"/>
<aura:attribute name="testRecType" type="Boolean"/>
<!-- Initialize event to handle calculating the boolean values-->
<aura:handler name="init" value="{!this}" action="{!c.doInit}" />
JS Controller
({
doInit : function(component, event, helper) {
component.set('v.testValue', (component.get('v.value') == 'test'));
//similar syntax for the recTypeName
}
})
Then your initializer will run every time the component begins. Or you can code a similar calculation in some other function for more frequent updates
You can use the aura:if and isTrue attribute as follows:
<aura:if isTrue="{!and(v.testValue, v.testRecType)}">
</aura:if>