Code By Code – Lightning Framework – Chapter 6 – Attributes, Expression

Code By Code – Lightning Framework – Chapter 6 – Attributes, Expression

Topics for this chapter:
– Aura Attributes
– Bound and Unbound Expression

Component Attributes makes your component more dynamic and can store values of different types which can be referred or accessed within component markup or controller javascript file. Consider these attributes like variables in an Apex class or method.
All attributes have a name and a type. Attributes may be marked as required by specifying required=”true”, and may also specify a default value.

An attribute name must follow these naming rules:
– Must begin with a letter or an underscore
– Must contain only alphanumeric or underscore characters

There are many different types which can be used within aura components. You can create:
– Boolean
– String
– Date
– DateTime
– Double
– Decimal
– Integer
– Long
– Object
– Set
– Map
– List
– Function
and all custom object, apex class, and standard object types.
You can declare an attribute like below:

<aura:attribute name=”showNew” type=”boolean” />

Expression allows you to access attribute values or make calculations within component markup. Expression can be used for dynamic output but does not support function calls.

You can access attribute values in two ways:
– Bound Expression – Uses 2-way data binding and fetches the new value of attribute automatically as soon as attribute value is modified by component. You can use the bound expression to access attribute value like below:


– Unbound Expression – Uses one-time data binding (do not confuse with one-way data binding), this means the expression will only hold the value at the time of initialization, and will never read new attribute data. You can use the unbound expression to access attribute value like below:

Update CarSearchForm.cmp component with below code:

Lightning Component Development Day3 - App, Attributes, Looping, Conditional Markup, Handling Events

Attributes and Expression

Manish Choudhari

I am a certified Salesforce Application & System Architect and Developer working on Salesforce Technology since 2014. Currently, I have 14 Salesforce certifications along with OCPJP (Oracle Certified Profession JavaSE6 Programmer) working in Hyderabad as a Technical Engineer. Writing technical blogs, learning new technologies and frameworks and sharing knowledge is my hobby.

This Post Has One Comment

Leave a Reply

Close Menu