Basic Types

Here are the supported basic type values. Some of these types correspond to the wrapper objects for primitives in Java. Since the framework is written in Java, defaults, such as maximum size for a number, for these basic types are defined by the Java objects that they map to.

type Example Description
Boolean <aura:attribute name="showDetail" type="Boolean" /> Valid values are true or false. To set a default value of true, add default="true".
Date <aura:attribute name="startDate" type="Date" /> A date corresponding to a calendar day in the format yyyy-mm-dd. The hh:mm:ss portion of the date is not stored. To include time fields, use DateTime instead.
DateTime <aura:attribute name="lastModifiedDate" type="DateTime" /> A date corresponding to a timestamp. It includes date and time details with millisecond precision.
Decimal <aura:attribute name="totalPrice" type="Decimal" /> Decimal values can contain fractional portions (digits to the right of the decimal). Maps to java.math.BigDecimal.

Decimal is better than Double for maintaining precision for floating-point calculations. It’s preferable for currency fields.

Double <aura:attribute name="widthInchesFractional" type="Double" /> Double values can contain fractional portions. Maps to java.lang.Double. Use Decimal for currency fields instead.
Integer <aura:attribute name="numRecords" type="Integer" /> Integer values can contain numbers with no fractional portion. Maps to java.lang.Integer, which defines its limits, such as maximum size.
Long <aura:attribute name="numSwissBankAccount" type="Long" /> Long values can contain numbers with no fractional portion. Maps to java.lang.Long, which defines its limits, such as maximum size.

Use this data type when you need a range of values wider than those provided by Integer.

String <aura:attribute name="message" type="String" /> A sequence of characters.

You can use arrays for each of these basic types. For example:

<aura:attribute name="favoriteColors" type="String[]" default="['red','green','blue']" />

Retrieving Data from an Apex Controller

To retrieve the string array from an Apex controller, bind the component to the controller. This component retrieves the string array when a button is clicked.
<aura:component controller="namespace.AttributeTypes">
    <aura:attribute name="favoriteColors" type="String[]" default="cyan, yellow, magenta"/>
    <aura:iteration items="{!v.favoriteColors}" var="s">
        {!s}
    </aura:iteration>
    <lightning:button onclick="{!c.getString}" label="Update"/>
</aura:component>
Set the Apex controller to return a List<String> object.
public class AttributeTypes {
    private final String[] arrayItems;
    
 @AuraEnabled
    public static List<String> getStringArray() {
        String[] arrayItems = new String[]{ 'red', 'green', 'blue' };
        return arrayItems;
    }

}
This client-side controller retrieves the string array from the Apex controller and displays it using the {!v.favoriteColors} expression.
({
    getString : function(component, event) {
    var action = component.get("c.getStringArray");
     action.setCallback(this, function(response) {
            var state = response.getState();
            if (state === "SUCCESS") {
                var stringItems = response.getReturnValue();
                component.set("v.favoriteColors", stringItems);
            }
        });
        $A.enqueueAction(action);
    }
})