Attributes in Lightning Components

Attributes in Salesforce Lightning Components




Component attributes are like member variables on a class in Apex. They are typed fields that are set on a specific instance of a component and can be referenced from within the component's markup using an expression syntax. Attributes enable you to make components more dynamic.

Attributes on components are like instance variables in objects. They’re a way to save values that change, and a way to name those value placeholders

Example
---------
<aura:attribute  name= "Name of Attribute"  type= "String"  default="world"/>

  • Name and type are a parameter of an attribute that is always required in attributes.
  • The description is another parameter where we can mention about description of an attribute. the description is not a required parameter. 
  • Similarly, we have a default parameter to give some default value to the attribute. 
  • To set the access for an attribute we have an access parameter where we can specify public, private, global access for an attribute. 
  • By default, the attribute has public access.
  • To make the attribute required we have a required parameter where we can set true or false.
Basic Attributes
---------------
1. Boolean
Syntax:
<aura:attribute name="name of attribute" type="Boolean" />
We can use the boolean attribute when we want to store boolean results.
2. Integer
Syntax:
<aura:attribute name="name of attribute" type="Integer" />
We can use the integer type attribute for storing integer type values.
3. String
Syntax:
<aura:attribute name="Anyname" type="String" />
We can store some text values inside the string type attribute.
ex: some text 1,some text2 etc.

4. Date
Syntax:
<aura:attribute name="Anyname" type="Date" />
5. DateTime
Syntax:
<aura:attribute name="Anyname" type="DateTime" />
6. Double
Syntax:
<aura:attribute name="Anyname" type="Double" />
To store fractional values.
7. Decimal
Syntax:
<aura:attribute name="AnyName" type="Decimal" />
Decimal is better than Double for maintaining precision for floating-point calculations. It’s preferable for currency fields.
8. Long
Syntax:
<aura:attribute name="AnyName" type="Long" />

Long values can contain numbers with no fractional portion. Use this data type when you need a range of values wider than those provided by Integer.



Like our post & bookmark this blog for your future learning. 

Any suggestions and improvements are most welcome, please comment your suggestions and improvement in the comment box. 

Happy Coding Sharing Is caring. 😀😀😀

Post a Comment

Post a Comment (0)

Previous Post Next Post