So, this is an error where I am kinda stuck with nowhere to go. I really donno how to resolve this as the code block looks all good to me. I am very new to lightning with only 2 days of lightning development experience, so please excuse me for any silly mistakes that I might have commited.
Here goes the component code:
<aura:component implements="flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId" access="global" controller="SearchContact">
<aura:attribute name="searchData" type="List"/>
<!--<lightning:input name="searchText"/>-->
<ui:inputText label="Enter the Search Text" value="Delete this and enter your keyword here" aura:id="{!v.searchText}" class="slds-input"/>
<lightning:button variant="brand" label="Search Contact" title="Search Contact" onclick="{!c.searchContact}" />
<lightning:card title="Contacts">
<p class = "slds-p-horizontal_small">
<aura:iteration items="{!v.searchData}" var = "contact">
<lightning:recordviewForm recordId="{!contact.Id}" objectApiName="Contact">
<lightning:outputField fieldName="Name"/>
<lightning:outputField fieldName="Phone"/>
<lightning:outputField fieldName="Email"/>
</lightning:recordviewForm>
</aura:iteration>
</p>
</lightning:card>
Below is the Controller
({
searchContact : function(component, event, helper) {
helper.fetchContacts(component, event, helper);
})
Helper :
({
fetchContacts : function(component, event, helper) {
//debugger;
var action = component.get("c.contactData");
var searchString = component.get("v.searchText");
//This is setting the value of the search keyword that is used in the apex controller
action.setParams({
keyword: searchString
});
action.setCallback(this, function(response){
var ContactList = response.getReturnValue();
component.set("v.searchData",ContactList);
});
//Global Action
$A.enqueueAction(action);
}
})
My Apex code looks like the below:
public class SearchContact {
@AuraEnabled
public static List<Contact> contactData(String keyword){
List<Contact> conData = [Select ID, Name, Phone, Email from Contact where FirstName =:keyword];
return conData;
}
}
I created a lightning App to get the results of the above component:
<aura:application extends="force:slds">
<skmondal:MyContactSearch/>
</aura:application>