SF LightningComponents Cheatsheet Web
SF LightningComponents Cheatsheet Web
SF LightningComponents Cheatsheet Web
Cheatsheet
Overview
The Lightning Component framework helps you build responsive UIs for Force.com apps. It uses JavaScript on the client side and Apex on the server
side. This framework is based on the Aura open-source framework.
<aura:component> can contain HTML or other Lightning <aura:if> Renders content within the tag if a
components. specified conditionis true.
In the handling component, add this handler: Get event parameter myEvt.getParam("myAttr");
<aura:handler event="namespace:theEvent" myEvt.setParams({ "myAttr" :
Set event parameters
action="{!c.updateEvent}"/> myVal});
Handle the event in a client-side controller.
updateEvent : function(cmp, event, helper) {
helper.updateObj(cmp,event.getParam("myObj"));
}
Core Form
Alternatively, use a component event to communicate These components are used in forms:
data to a parent component. Retrieve the event using cmp. An HTML button element used to
getEvent("cmpEvent") and fire it. <ui:button> submit a form or
execute an action.
An HTML input element of type
<ui:inputCheckbox>
checkbox.
Expressions
An HTML input element for entering
<ui:inputDate>
Use the {!...} syntax to evaluate an expression. For example, a date.
{!c.change} calls a client-side controller and {!v.myText} An HTML input element for entering
<ui:inputDateTime>
refers to a component attribute value. {!v.body} outputs the a date and time.
body of the component, which is an array
<ui:inputEmail> An HTML input element of type email.
of components.
An HTML input element for entering
<ui:inputNumber>
a number.
An HTML input element for a phone
CSS <ui:inputPhone>
number.
Use the .THIS selector with your CSS declarations to prevent styling <ui:menu> An HTML select element.
conflicts. .THIS is replaced by your component name at runtime.
A drop-down list with a trigger that
.THIS h1 { <ui:inputSelect>
padding-left: 40px; controls its visibility.
}
Core Output
Static Resources These components are used for outputting values:
Place resources in a .zip file and upload to Static Resources. <ui:outputCheckbox> Displays a read-only checkbox in
Reference a JS or CSS resource using: a checked or unchecked state.
<ltng:require scripts="{!$Resource.jsResourceName}" <ui:outputDate> Displays a date based on locale.
styles="{!$Resource.cssResourceName}"
<ui:outputDateTime> Displays a date and time based
afterScriptsLoaded="{!c.afterScriptsLoaded}" />
on locale.
Use yourNamespace__resourceName if you have a registered
<ui:outputEmail> Displays an email address in an
namespace.
HTML anchor element.
The afterScriptsLoaded event calls a controller action after the
scripts are loaded. <ui:outputNumber> Displays a number based on locale.
<ui:outputPhone> Displays a phone number in an
HTML anchor element.
<ui:outputText> Displays a string of text.
Common $A Methods Calling and Apex Controller
The Aura object is the top-level object in the JavaScript framework
Apex controllers are called from client-side controllers.
code. $A is shorthand for Aura.
The getOpps client-side controller action calls the
$A.get() Returns an app-level event. getOpportunities Apex controller action.
$A.enqueueAction() Queues an action for batch execution. "getOpps" : function(component) {
$A.createComponent() Dynamically creates a component. var a = component.get("c.getOpportunities");
Wiring a Component to a Controller To make a component available for Lightning Experience, create
a custom Lightning Component tab for the component, and
Add a controller system attribute to the <aura:component> assign it to an app via Create > Apps. The component will be
tag to wire a component to an Apex controller. For example: available in the App Launcher.
<aura:component controller="myNamespace.
MyApexController">
developer.salesforce.com