Custom Label use in Aura
Make sure you have created the Custom Label like in the below example its called Sample with value Hello EveryOne!
Apex Cass:
public with sharing class LabelController {
@AuraEnabled
public static String getLabel() {
String str = System.Label.Sample;
return str;
}
}
@AuraEnabled
public static String getLabel() {
String str = System.Label.Sample;
return str;
}
}
Aura Component:
labelAuraSample Aura:
js:
({
doInit : function(component, event, helper) {
var action = component.get("c.getLabel");
action.setCallback(this, function(response) {
var state = response.getState();
if (state === "SUCCESS") {
component.set("v.mylabel", response.getReturnValue());
}
// error handling when state is "INCOMPLETE" or "ERROR"
});
$A.enqueueAction(action);
}
})
doInit : function(component, event, helper) {
var action = component.get("c.getLabel");
action.setCallback(this, function(response) {
var state = response.getState();
if (state === "SUCCESS") {
component.set("v.mylabel", response.getReturnValue());
}
// error handling when state is "INCOMPLETE" or "ERROR"
});
$A.enqueueAction(action);
}
})
html:
<aura:component controller="LabelController">
<aura:handler name="init" value="{!this}" action="{!c.doInit}" />
<aura:attribute name="mylabel" type="String"/>
{!v.mylabel}
</aura:component>
<aura:handler name="init" value="{!this}" action="{!c.doInit}" />
<aura:attribute name="mylabel" type="String"/>
{!v.mylabel}
</aura:component>
To check the output create an app may be and preview:
<aura:application >
<c:labelAuraSample/>
</aura:application>
Reference: https://thesalesforcetutorial.blogspot.com/2023/02/custom-labels-insalesforce.html
Comments
Post a Comment