Monday, February 6, 2017

How to use conditional statements IF, Else in lightning components?.

How to use conditional statements IF, Else in lightning components?.


In the below example components I am using IF and Else conditions in components.

IFComp:



In the above screen shot I am using aura:attribute  to define variable with name as “change”, data type as boolean for this I assigned a default value as TRUE.
In line number seven I am starting IF condition with <aura:if> tag. If you want to define conditional expression in lightning components we have to use <aura:if>  . if the change variable value is TRUE then I am displaying button with test as “I am True”, else I am displaying button with label as “I am false”
In line number ten I am using else block for the above if condition, for this we have to use the tag of <aura:set attribute=”else”/>


<ui:button> is used to create buttons in lightning components.

Output 1: 

Here I will the button the button label as true, because of I assigned default value for the “Change” variable as true.



Output 2:











1 comments:

Post a Comment

 
| ,