In this tutorial, I am going to show you how to use Attribute in Lightning Component Salesforce. Attributes in Lightning Component can be thought as a member variable of a class. This has some type and used to store data.
Attribute in Lightning Component Salesforce:
Attributes in Lightning Component can be thought as a member variable of a class. This has some type and used to store data.The attribute can be used for creating a dynamic component. <aura:attribute> tag is used for creating an attribute in a lightning component. To use the value of an attribute we use the expression syntax.
The syntax for declaring Attribute in Lightning Component Salesforce:
<aura:attribute name="attrname" type="String" default="test value" description="description goes here" access="public"/>
Where,
name (required): Name of an attribute.
type (required): Type of information to be stored.
default(optional) : Default value of an attribute.
access (optional): Indicates whether the attribute can be used outside of its own namespace. Possible values are public (default), and global, and private.
description (optional): Summary of an attribute and its usage.
required (optional): represent a boolean value. Determines if the attribute is required. The default is false.
Access attribute in Lightning Component.
To access attribute in Lightning Component use the expression:
{!v.attrname}
Example of Attribute in Lightning Component:
Create a lightning component called Attribute Demo.
<aura:component > <aura:attribute name="FirstName" type="String" default="Vivek Singh" /> <aura:attribute name="Age" type="Integer" default="25"/> <aura:attribute name="isMale" type="Boolean" default="true"/> <p>Name {!v.FirstName}</p> <p>{!v.FirstName} is {!v.Age} Years Old.</p> <p>{!v.FirstName} is male? = {!v.isMale}</p> </aura:component>
Create an App called TestApp and write the following code:
<aura:application extends="force:slds" > <c:AttributeDemo/> </aura:application>
Run the App and see the output:
Naming Convention for Attribute in Lightning Component:
An attribute name must follow these naming rules:
- Must begin with a letter or an underscore.
- Must contain only alphanumeric or underscore characters.
View More:
- How to dynamically bind picklist field value in Lightning Component.
- How to Implement Pagination in Lightning Component Salesforce.
- Display Record List in Lightning Component Salesforce.
- How to fetch records from sobjects using REST API in apex class salesforce.
Conclusion:
I hope you would love this post. Please feel free to comment for any technical help. Your feedback and suggestions are important for us.
Thank You.
erection pills canadian pharmacies mens ed pills
board of pharmacy pharmacies online canadian pharmacy
pharmacies near me best drugstore face moisturizer 24 hr pharmacy
medicine for erectile pharm rx pharmacy coupons
erectile dysfunction causes my canadian pharmacy canadian drug pharmacy
pharmacy canada drug pharmacy rx pharmacy
online drugstore pharmacy 24 hour pharmacy canadian mail order pharmacy