LIGHTNING AURA ATTRIBUTE

Salesforce lightning aura attribute


Aura attribute is the first thing you need to define in your salesforce lightning component.
Similar to the variable declaration with its data type, we will define a variable first and we will use that variable in further code.

So let's get started, we will use <aura:attribute/> tag to define aura attribute.

The example of the aura attribute is :
=================================================
<aura : attribute name="Num1" type="Integer"/>
=================================================

So as you can see in the above example aura attribute tag is defined as <aura:attribute>, Where name and type are required whenever you are defining aura attribute in salesforce.

Now to access this variable Num1 and display value hold by attribute we use {!v.Num1}, Where {!v.xxxis used to get value hold by attribute.

So basically lightning aura attributes are used to display something on front-end in application or component and for the back-end, we will use a .js controller. 

Hence you can also define your aura attribute inside a lightning application.

For Example :
=============================================

<aura:application>

    <aura:attribute name="salesforcekid" type="String" default="World"/>

  <h1>

    Hello {!v.salesforcekid}!

  </h1>

</aura:application>

=============================================

Output :

=============================================

Hello World

=============================================
  • Now something interesting and my favorite that is to display Button or Textbox on lightning component.
  • So to display button we use <ui:button/> tag with a label and to provide the action after clicking of a button you need to call client side controller i.e. .js controller method.
  • Don't worry because we are gonna cover that as well.
  • Button press action is defined as press="{c.method}" to call a method from client-side controller.
  • For Example :
=============================================
<aura:component>
  <aura:attribute name="name" type="String"/>
   <h1>
        Welcome to salesforce {!v.name}
     </h1>
      <ui:button label="Click Me" press="{!c.myname}"/>
   
</aura:component>
=============================================
  • Above component will call myname method from .js controller and provide value to {!v.name}.
  • We will see how to set a value into an attribute and display the result in the upcoming episodes of this series.
  • So the output of the above aura component is like this :
=============================================
Welcome to salesforce kid
=============================================

In this way, you can create and use aura attribute in salesforce lightning

WOHOOOO.......YOU HAVE JUST COMPLETED LIGHTNING AURA ATTRIBUTE EPISODE
If you like this salesforcekid learning platform please let me know in the Comment section...Also, Share with your salesforce folks wish you 
Happy learning ☁️⚡️ (Learn. Help. Share.)


<< PREVIOUS                                                      NEXT >> 

  
LIGHTNING AURA ATTRIBUTE LIGHTNING AURA ATTRIBUTE Reviewed by on Rating: 5

No comments:

HELP !! SHARE !! SUGGEST !!

Powered by Blogger.