Code By Code – Lightning Framework – Chapter 15 – Aura Method

Code By Code – Lightning Framework – Chapter 15 – Aura Method

Topics for this chapter:

  • Aura Method – Parent to Child Communication
  • Ternary Operator

In our chapter 13, we have learned about component events which were used for child to parent communication in the same component hierarchy. Similar way aura:method is a lightning way to communicate down the component hierarchy.

This enables you to directly call a method in a component’s client-side controller. Use aura:method to communicate down the containment hierarchy. For example, a parent component calls an aura:method on a child component that it contains.
The tag has these system attributes
name – (String) : The method name.
action – (Expression) : The client-side controller action to execute.
access – (String) : Access control for the method. Global or Public

NOTE: aura:method can also have attributes which act as method parameters, and can also return values to parent component.

Handle if-else condition with ternary operator in component markup.
{! Condition ? true : false}

{! v.selected ? ’tile selected’ : ’tile’}
– If selected=true, then apply stylesheets ‘tile’ and ‘selected’
– If selected=false, then apply stylesheet ‘tile’

Component Markup

Component Controller

Component Markup

Component Controller

Component Helper

Apex Controller

The CarSearch component is the parent component of CarSearchForm and CarSearchResult component.  It has the aura:handler to handle the component event being fired from CarSearchForm. It also fires the aura method of CarSearchResult component.

The CarSearchResult component is child component of CarSearch component. It has an Apex Controller “CarSearchController” to perform server-side tasks like get car and owner information.

This component also has an aura:method which is being called from parent “CarSearch” component. This aura:method calls a controller action which further calls the helper method.

CarSearchResult component is a parent of CarTile component which displays car image and information.

Lightning Component Development Day7 - Aura Method, Understand Layouts, Call Child Component Action

Aura Method

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.

Leave a Reply

Close Menu