You need to sign in to do that
Don't have an account?
Kevin Jackson 11
how to reference userid in lightning component
Hi, I am trying to a field from the active user in a component and use it in an if statement.
<aura:if isTrue="{!$User.IsActive}">
<td class="button"><a href="#" target="_blank">
<lightning:button label="Join"/></a></td>
<aura:set attribute="else">
<td class="button"><a href="#" target="_blank">
<lightning:button label="Renew Membership"/></a></td>
</aura:set>
</aura:if>
I assume I am using the wrong syntax for {!$User.IsActive} as it always throws up the else and IsActive is definitely TRUE for the current user.
Thanks for any help
<aura:if isTrue="{!$User.IsActive}">
<td class="button"><a href="#" target="_blank">
<lightning:button label="Join"/></a></td>
<aura:set attribute="else">
<td class="button"><a href="#" target="_blank">
<lightning:button label="Renew Membership"/></a></td>
</aura:set>
</aura:if>
I assume I am using the wrong syntax for {!$User.IsActive} as it always throws up the else and IsActive is definitely TRUE for the current user.
Thanks for any help
Wouldn't the user always be active if they can open your component?
Anyway, the $User global is not available in Lightning Components.
If you need to retrieve details about the User you will need to add an Apex controller with an @AuraEnabled method which returns those details to your component, something like: You can then call this method from your JavaScript controller, with a callback method to update an attribute in your component that you can use in your aura:if tag, see here:
https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/controllers_server_actions_call.htm
Thanks for the info (and the code) I will give it a try.
I need a little extra help. I added the code to my controller, but I am not sure how to set the variable to the current state in my component. Would you be able to post a small snippet on how I would call it?
Thanks.
Then, in your JavaScript controller, you'll need a "doInit" method that fires your AuraEnabled Apex method:
Here the controller code for the lightning
simply use this statement. Same thing I have posted on my blog, please check out my post (http://allaboutlightning.com/get-current-user-id-information-in-lightning/)
Thanks
Pramodh
allaboutlightning.com
Do you know if exists another way like this to get the profile info without asking the server?
I am searching and don´t find anything