+ Start a Discussion
charbel ALALAMcharbel ALALAM 

how to get a reference to custom label in lwc dynamically

hi guys, 
i have a question plz:
How can i get a reference to a custom label dynamically using lwc:
i have this code and i want to convert it to lwc:
var currentCat = categoryWrapper.categories[i];  var labelReference = $A.getReference("$Label.c."+currentCat.name);   component.set("v.tempLabel", labelReference);
//we can't use $A.getreference in lwc,
 and using apex i didn't found a solution 
this is the function in apex:
 @AuraEnabled     public static String getLabel(String LabelName){                  system.debug('LabelName'+LabelName);  
      String s2 = system.Label.LabelName ;  return s2;     }
this is the function in lwc:
                    LabelName:labelReference, //labelreference is the name of custom label
//i want to return the value of a custom label when i send the name of custom label in parameter. Where Is my error, and is there a solution ?
Best Regards

Hi Charbel,

Please check with below link for accessing label in LWC


Once you get the label, you can rendered it based on the requirement.


Hope this helps,