About

Edit photo

Thursday, November 9, 2017

Retrieving lightning component tips


How to get Lightning Button label?
<lightning:button label="Get Label" onclick="{!c.getLabel}" aura:id="button1" />  
<aura:attribute name="buttonLabel" aura:id="btn1" type="String"/>

 var BtnLabelWay1 = event.getSource().get("v.label"); -- Used when any Action event occurs, ex: onClick  
 var BtnLabelWay2 = component.find("button1").get("v.label");          -- Can use when auraID exist  

Get and Set Attribute Value
 var att1 = component.get("v.buttonLabel"); -- Getting attribute   
 var att1 = component.find("btn1"); -- Getting attribute using aura:ID  
 component.set(att1,"this is the value for the buttonLabel"); -- Setting attribute with value   

Attribute is empty or not?
 var isEmpty = $A.util.isEmpty(cmp.get("v.label"));  


0 comments:

Post a Comment