2

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>
0

3 Answers 3

1

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

4
  • This does not work either Jun 14, 2019 at 15:46
  • Thank you so much I had tried in a very similar way. But without success kk
    – Barbilque
    Jun 14, 2019 at 15:47
  • Please update your original question with the error message, and make sure that both values you are using in the condition are set. Jun 14, 2019 at 15:48
  • I've edited my answer to use the equal function as well. If it still throws you an error, it is likely a problem outside this expression. Jun 14, 2019 at 15:49
3

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 &amp;&amp; in that case.

However, it is recommended that you use and(condition). This is from the documentation:

&amp;&amp; This syntax is awkward in markup so we recommend using the and function instead.

0

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>
2
  • The operators do work in aura expressions, though.
    – sfdcfox
    Jun 14, 2019 at 16:31
  • Thanks, edited. Jun 14, 2019 at 16:37

You must log in to answer this question.

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