2

I am calling apex class and i need to pass the returned values to another component. But i am not sure how the logic works here. Is it the $A.enqueueAction fires before $A.fire() or vice-versa.

    //Controller.js
onLoadAction :function(component, event){
    var evt = $A.get("e.force:navigateToComponent);
    var op =component.find("option_holder");
    var valu = op.get("v.value");
    var apex = component.get("c.getAccountList);
    apex:setParams({
        "option":"valu"
    });
    apex:setCallback(this, function(resp){
        if(resp.getState()="SUCCESS"){
            //Now i want to navigate to next component with returned values.
            evt.setParams({
                "componentDef" : "AccListComponent",
                "componentAttributes":{
                    "accList":resp.getReturnvalue();
                } // DO I NEED TO PLACE EVT.FIRE HERE???
            });
        }
    });
    $A.enqueAction(apex);
    evt.fire();
}

I mean i am just blank here. which one to place first in real time scenarios. Please suggest.

1 Answer 1

1

Yes you are correct here because in Lightning Apex calling is in asynchronous mode so after calling the $A.enqueAction(apex); it doesn't wait for processing to complete and fire the event.

As to handle these type of scenario we have callback functionality in Lightning.

So you need to fire your event from inside the callback function.

apex.setParams({
        "option":"valu"
    });

action.setCallback(this, function(resp){
        if(resp.getState()="SUCCESS"){
            //Now i want to navigate to next component with returned values.
            evt.setParams({
                "componentDef" : "c:AccListComponent",
                "componentAttributes":{
                    "accList":resp.getReturnvalue();
                } 
            });
            evt.fire();
        }
    });
    $A.enqueAction(apex);

Also be aware about case sensitive as lightning is case sensitive.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .