Display Loggedin User details without Apex in Aura

Component:
<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,force:lightningQuickAction" access="global" >
    <aura:attribute name="currentUser" type="User" />
    <force:recordData
                      fields="Username,Name, Email"
                      recordId="{!$SObjectType.CurrentUser.Id}"
                      targetFields="{!v.currentUser}"
                      mode="VIEW"
                      />     
    <lightning:button variant="brand" label="Load Report" onclick="{! c.handleClick }" />
</aura:component>
Controller:
({
    handleClick : function(component, event, helper) 
    {
        var UserName =  $A.get("$SObjectType.CurrentUser");		
        alert(' User Name--- '+component.get("v.currentUser.Username"));   
        alert(' Name --- '+component.get("v.currentUser.Name"));     
    }
})

Comments

Post a Comment