0

I have lightining component code and Controller

Component code:

<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" controller="acquisitiondeallightningcntrl">
<aura:attribute name="deal" type="Acquisition_Deal__c[]"/>
    <aura:attribute name="primarytermsid" type="Primary_Terms__c"/>

   <aura:registerEvent name="navEvt" type="force:navigateToSObject"/>
     <aura:attribute name="recordId" type="Id" />
    <aura:attribute name="idx" type="String" />


            <aura:handler name="init" action="{!c.doInit}" value="{!this}"/>
               <table class="slds-p-around_x-small slds-text-body_small slds-table slds-table--bordered slds-table--fixed-layout " >
                   <thead>
                       </thead> 
                    <tbody>

                        <tr class="slds-hint-parent" >
                        <td><lightning:button variant="brand" label="Acquisition Deal" onclick="{!c.navigate}"/>


                        </td>


                           </tr>            

                    </tbody>
                </table>
</aura:component>

Controller:

({
 doInit: function(component, event, helper) {
     helper.method1(component, event, helper)

 }});

Helper:

({
     method1: function(component, event, helper) {

         var action = component.get("c.getdealid");
         action.setParams({
             "primarytermsid": component.get("v.recordId")
         });
         console.log("RecordID####" + component.get("v.recordId"));
         action.setCallback(this, function(response) {
             var state = response.getState();
             if (component.isValid() && state === "SUCCESS") {

                 component.set("v.idx", response.getReturnValue());
                 helper.navigate(component, event, helper);
             } else {
                 console.log("Failed with state: " + state);
             }

         });
         $A.enqueueAction(action);
     },
 navigate: function(component, event, helper) {
     var idx = component.get("v.idx");

     var navEvt = $A.get("e.force:navigateToSObject");
     navEvt.setParams({
         "recordId": idx,
         "slideDevName": "detail"
     });

     navEvt.fire();
 }
} )

The Action is performing whenver the page loads, i want to perform the same action after clicking button How to rectify this issue?

1

You have to call the method like this:

instead of "doInit" write "Navigate" in controller

navigate:function(component, event, helper) {
 helper.method1(component, event, helper)
 }});
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.