You need to sign in to do that
Don't have an account?
Alen hilston
How to add conditionl statements in Aura:if
Hi,
Please help. I am trying to add some conditional statement like in vfpage on my aura component but I am not able to do it. It keeps showing me the same error.
<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" > <aura:attribute type="Integer" name="score"/> <aura:if isTrue="{!v.score > 0 && v.score < 10}"> <b>You are not eligible</b> </aura:if> </aura:component>
Please let me know if I am doing something wrong!
Yes, you can use the value of one attribute and set the value of another attribute by using below code :
<aura:attribute name="one" type="String"/> // value which is to be checked
<aura:attribute name="two" type="String" default="{!if(v.one== 'this','raised','not raised')}"/> // attribute whose value is to set default.
Here we have checked the value of one and based on this value we have set the default value of attribute two.
I hope it helped you. It would be nice if you mark it as the best answer.
Thanks.
All Answers
Hi Alen,
Hope you are doing well.
We cannot add similar conditions in Aura as we do on the VF page. In the Aura component, we have different formats and statements for conditional statements. In the aura component, we use pre-build conditional expressions.
The above condition can be fulfilled by making condition into this format given below:
<aura:if isTrue="{! and( greaterthan(v.score,0), greaterthan(10,v.score) ) }">
For further more information, you can refer to this link given below:
https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/expr_conditional.htm
Hope this will resolve your answer.
Please could you mark it as the best answer if it resolves your query?
Thanks.
Hi Suraj,
Thanks, It worked. Could you please let me know if there's anything i can do to set default values of attribute on the basis of another attribute?
Yes, you can use the value of one attribute and set the value of another attribute by using below code :
<aura:attribute name="one" type="String"/> // value which is to be checked
<aura:attribute name="two" type="String" default="{!if(v.one== 'this','raised','not raised')}"/> // attribute whose value is to set default.
Here we have checked the value of one and based on this value we have set the default value of attribute two.
I hope it helped you. It would be nice if you mark it as the best answer.
Thanks.