1

I am not able to find where i am doing wrong.

i have a parent component A with two child components B and C

my scenario is to fire an event in window.setTimeout of component B and send it to component C

    var PhaseVar = component.get('v.Phase');
    var PEvent = component.getEvent('pEvent');
    var delay= 6000;
    console.log('PhaseVar :'+PhaseVar ); // i am able to get value
     console.log('PEvent :'+PEvent ); // i am able to get value
    window.setTimeout(
    $A.getCallback(function(){
    var PhaseVar = component.get('v.Phase');
    var PEvent = component.getEvent('pEvent');
    console.log('PhaseVar :'+PhaseVar ); // returning null
    console.log('PEvent :'+PEvent ); // returning null

       pEvent.setParams({
                    'data':{
                        'Error':  'xxxxxx',
                        'Phase': 'yyyyy'

                    } 
                });
                console.log('event  : ');
                PEvent.fire(); // not working 
        }), delay
    );   

If I try get any of the component related things like attributes or events inside the timeout i am getting null and if i keep out side the timeout unable to fire the event.

need help me in fixing this

  • you seem to have an extra closing brace? In JavaScript 80% issues could be caused by Indentation.. – Raul Jun 12 at 13:11
  • sorry i made changes, extra close brace might not be the issue. – raghava ravipati Jun 12 at 13:18
0

You have to pass, component ,PmtSrnEvent and other variable to setTimeout. The reason being setTimeout runs in different context asyn and cant find the local variable to your function.

window.setTimeout(
    $A.getCallback(function(component , PmtSrnEvent){
    var PhaseVar = component.get('v.Phase');
    var PEvent = component.getEvent('pEvent');
    console.log('PhaseVar :'+PhaseVar ); // returning null
    console.log('PEvent :'+PEvent ); // returning null

       PmtSrnEvent.setParams({
                    'data':{
                        'Error':  'xxxxxx',
                        'Phase': 'yyyyy'

                    } 
                });
                console.log('event  : ');
                PEvent.fire(); // not working 
            }                
        }), delay , component , PmtSrnEventPmtSrnEvent
    );   

Src: https://stackoverflow.com/questions/32326721/pass-parameter-to-settimeout-callback-function/32326935

  • Hi Pranay, thank you for responding. i tried this already and i tried after you comment as well. i am getting Cannot read property 'get' of undefined. – raghava ravipati Jun 12 at 13:30

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.