In this module, you create a Lightning Component responsible for displaying the list of contacts and you add the ContactList component to the QuickContacts component.
In the Developer Console, click File > New > Lightning Component. Specify ContactList as the bundle name and click Submit
Implement the component as follows:
<aura:component controller="ContactListController">
<aura:attribute name="contacts" type="Contact[]"/>
<aura:handler name="init" value="{!this}" action="{!c.doInit}" />
<ul>
<aura:iteration items="{!v.contacts}" var="contact">
<li>
<a href="{! '#/sObject/' + contact.Id + '/view'}">
<p>{!contact.Name}</p>
<p>{!contact.Phone}</p>
</a>
</li>
</aura:iteration>
</ul>
</aura:component>
### Code Highlights:
<aura:iteration>
is used to iterate through the list of contacts and create an <li>
for each contactClick File > Save to save the file.
Click CONTROLLER
Implement the Controller as follows:
({
doInit : function(component, event) {
var action = component.get("c.findAll");
action.setCallback(this, function(a) {
component.set("v.contacts", a.getReturnValue());
});
$A.enqueueAction(action);
}
})
### Code Highlights:
Click File > Save to save the file
In the developer console, go back to the QuickContacts component.
If you don’t see the tab in the developer console, click File > Open Lightning Resources in the Developer Console menu, select QuickContacts > COMPONENT in the dialog, and click the Open Selected button.
Replace the ContactList placeholder with the actual component:
<aura:component implements="force:appHostable">
<c:ContactList/>
</aura:component>
c: is the default namespace for Lightning components
Click File > Save to save the file
Go back to the Salesforce1 app and reload Quick Contacts from the menu to see the changes:
In this step, you’ll add some CSS styles to the component to make it look like a standard mobile list. You’ll remove the item bullets, add a horizontal line between items, and fine tune margins.
Click STYLE
Implement the following styles:
.THIS {
list-style-type: none;
padding: 0;
margin: 0;
}
.THIS li {
border-bottom: solid 1px #DDDDDD;
padding: 8px;
}
.THIS p {
margin: 4px;
}
Click File > Save to save the file
Go back to the Salesforce1 app and reload Quick Contacts from the menu to see the changes: