Get field label in lightning component

I need to get and use the field label in my lightning component.

In VF it is possible to do this via the:

{!$ObjectType.Account.fields.Title.Label} 

OR:

{!$ObjectType['Account'].fields['Title'].Label}

How can this be done in lightning component markup or controller?

Answer

You need to call server side controller from lightning and use following code (Describe API) there:

Schema.SObjectField F = fieldNameMap.get(fieldAPIName); //where fieldAPIName is API name of field
Schema.DescribeFieldResult R = F.getDescribe();
String fieldLabel=R.getLabel();
return fieldLabel;

This is the only way as far as I know. Else, you can create new custom labels for field names labels and use them directly in lightning using “$Label.c.Custom_Label”

Attribution
Source : Link , Question Author : Itai Shmida , Answer Author : Sarang

Leave a Comment