Last active
November 21, 2016 16:49
-
-
Save dancinllama/83883a73bead6e3adb5e4d6a95d33baa to your computer and use it in GitHub Desktop.
Component for displaying Contact Name(s)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* ContactsCtrl | |
* @description Apex and stuff.. | |
* @author | |
* @date 11/21/2016 | |
*/ | |
public with sharing class ContactsCtrl { | |
@AuraEnabled | |
public static List<Contact> getContacts(){ | |
return [Select Name From Contact Limit 5]; | |
} | |
@AuraEnabled | |
public static Contact getCurrentContact(){ | |
User u = [Select Contact.Name From User Where Id=:UserInfo.getUserId()]; | |
return u.Contact; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
({ | |
doInit : function(component, event, helper) { | |
//Call action to get a list of contacts via Apex. | |
var action = component.get("c.getContacts"); | |
action.setCallback(this,function(a){ | |
if(a.getState() === "SUCCESS"){ | |
component.set("v.contacts",a.getReturnValue()); | |
} | |
}); | |
$A.enqueueAction(action); | |
//Call action to get current contact's name. | |
var action2 = component.get("c.getCurrentContact"); | |
action2.setCallback(this,function(a){ | |
if(a.getState() === "SUCCESS"){ | |
component.set("v.currentContact",a.getReturnValue()); | |
} | |
}); | |
$A.enqueueAction(action2); | |
} | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<aura:component implements="forceCommunity:availableForAllPageTypes" controller="ContactsCtrl"> | |
<aura:attribute name="contacts" type="Contact[]" /> | |
<aura:attribute name="currentContact" type="Contact" /> | |
<!-- example for displaying list of contacts --> | |
<aura:iteration items="{!v.contacts}" var="contact"> | |
<ui:outputText value="{!contact.Name}" /> | |
</aura:iteration> | |
<!-- example for display current contact's name --> | |
Hello, {!v.currentContact.Name}! | |
</aura:component> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment