4

I know that in vf i can dynamically obtain the value of a label like this :

<apex:outputText> {!$Label[mylabel]} </apex:outputText>

But this does not work in lightning :

    $A.get("$Label.c['customerInformation']")

nor this :

 $A.get("$Label.c[my_variable]"));

Has anyone been able to do it?

2

What i wanted to do, in fact exist on lightning, here is the code :

 var labelSubStr = "task_mode_today";
 var labelReference = $A.getReference("$Label.c." + labelSubStr);
 cmp.set("v.tempLabelAttr", labelReference);
 var dynamicLabel = cmp.get("v.tempLabelAttr");

Here is the link to the doc : https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/labels_dynamic.htm

1

As i'm using a visualforce page to contain my lightning component. I evaluated my labels dynamically in my vf controller using the following method like this :

 public string getLabel(object o){      
    Component.Apex.OutputText output = new Component.Apex.OutputText();
    output.expressions.value = '{!$Label.' + string.valueOf(o) + '}';
    return String.valueOf(output.value);
}

This method use the output.expressions.value variable which can only be used in a visualforce class controller.

I processed all my required labels via this method and return a map of those label as an object to my lightning component

0

Doing this: https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/labels_value_provider_platform.htm works for me.

Just try this: console.log($A.get("$Label.namespace.labelName"));

  • console.log($A.get("$Label.namespace.labelName")); doesn't work for me. Forget about the dynamic, the static one isn't working either :( – vanessen Aug 2 '16 at 14:51
  • Even if you call an apex controller method that returns that label content doesn´t work for you? – D. Cruz Aug 2 '16 at 14:54
-1

I was able to find this on the Developer Pages.

I think what you are looking for is the following:

Labels In Lightning

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.