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

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

Chapter 6

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

Aura Attributes

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” />

Bound And Unbound Expression

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:

{!v.showNew}

– 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:

{#v.showNew}

Update CarSearchForm Component

Update CarSearchForm.cmp component with below code: https://gist.github.com/cb28b659c97818be1d551339af17fe51

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

Test Your Knowledge

Attributes and Expression

Next In This Guide

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 Salesforce.com 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