Below is code snippet on using custom labels in Lightning Web Components.
Assume, we have custom label named welcomeText and exitText
In Javascript file of LWC, we have to follow below syntax
// CustomlabelExample.js
import { LightningElement } from 'lwc';
// Import custom labels
import welcomeText from '@salesforce/label/c.welcomeText';
import exitText from '@salesforce/label/c.exitText';
export default class CustomLabelExample extends LightningElement {
// Expose the labels to use in the template.
label = {
welcomeText,
exitText
};
}
Notice, how we imported label and used c. if there is no namespace.
import welcomeText from '@salesforce/label/c.welcomeText';
<!-- CustomlabelExample.html -->
<template>
Hi , {label.welcomeText} !!!
<!-- some more code -->
Sorry to see you going, {label.exitText}
</template>
Reference :
Leave a Reply