How to display Custom Labels in Lighting (Aura) Components

Syntax

$Label.namespace.LabelName
if your org not having any names space use default namespace ‘c’

Let us create a custom label with name Label1

Lightning Component

<aura:component implements="flexipage:availableForRecordHome,force:hasRecordId" access="global" >
    <aura:attribute name="strLabelvalue" type="String" />
    <!-- System handler -->
    <aura:handler name="init" value="{!this}" action="{!c.getLabelValue}" />

<center>
    <div class="slds-theme_default">
        <!-- Custom Label value from component -->
        <h2  class="slds-text-heading_medium slds-m-bottom_medium">Custom Label value from Lightning Component</h2>
        <p><b>{!$Label.c.Label1}</b></p><br/><br/>

        <!--Custom Label value from Controller -->
        <h2  class="slds-text-heading_medium slds-m-bottom_medium">Custom Label value from Controller</h2>
        <p><b>{!v.strLabelvalue}</b></p>
    </div>
</center>
</aura:component>

Controller

({

getLabelValue : function(component, event, helper) {

var labelValue = $A.get(“$Label.c.Label1”);

component.set(‘v.strLabelvalue’, labelValue); },

})

Permanent link to this article: https://salesforcebuddy.com/2020/01/how-to-display-custom-labels-in-lighting-aura-components/

Leave a Reply

Your email address will not be published.