I am not able to pass the parameter from lightning controller to apex controller. In below apex controller "accNo" is null where as in lightning controller I am getting value of accountNumber. Don't know whats wrong in my code. Please help.
Apex Controller
@AuraEnabled
public static Banking__c searchAccountApex(String accNo){
system.debug(accNo);
Banking__c searchbank = [select Account_Name__c,Balance__c, from banking__c where name = :accNo ]; // Getting accNo null
return searchbank;
}
Component
<aura:component controller="Bank_Controller">
<aura:attribute name="AccountNumber" type="String" default=""/>
<aura:attribute name="record" type="Banking__c" default="{'sobjectType':'Banking__c', 'Account_Name__c':'','Deposit_Amount__c':''}"/>
<aura:attribute name="searchResult" type="boolean" default="false" />
<ui:inputNumber label="Account Number" aura:Id="accountNumber1" value="{!v.AccountNumber}" class="Account_Number__c" />
<ui:button label="search" press="{!c.searchAccount}" /> <br></br>
<aura:if isTrue="{!v.searchResult}">
Account Name : <ui:outputText value="{!v.record.Account_Name__c}" /> <br></br>
Account number : <ui:outputText value="{!v.record.name}" /> <br></br>
Account Balance : <ui:outputCurrency value="{!v.record.Balance__c}" /> <br></br>
</aura:if>
</aura:component>
JavaScript Controller
({
searchAccount : function(component, event, helper) {
var accountNumberComponent=component.find("accountNumber1");
var accountNumber = accountNumberComponent.get("v.value");
console.log(accountNumber); // getting account number using component.find method
console.log(component.get("v.AccountNumber")); // getting account number directly from accoountNumber Attributr
var action = component.get("c.searchAccountApex");
action.setParams({
accNo : component.get("v.AccountNumber") // Here when if I pass "AccountNumber" attribute, it is not getting passed. getting null in apex controller.
});
action.setCallback(this,function(response){
if(response.getState()==="SUCCESS"){
component.set("v.record",response.getReturnValue());
component.set("v.searchResult",true);
}
});
$A.enqueueAction(action);
}
})
System.debug
in the apex method and checked the value ofaccNo
?