5

I just want to refresh my data in lightning component for every 1 mins. Like auto refresh. My test case like 'Want to display employees who are in inactive for every 1 min using Lightning component'

2 Answers 2

7

You can create a function that you will call in init and in this function you need to add a setTimeout for 1 minute which will call this same function

controller :
doInit: function(component, event, helper){
   helper.everyMinute(component);
}

helper:
everyMinute:  function(component){
   var that = this;
   //put your code here and in setCallback add setTimeout with 1 minute

   var action = componet.get('c.getData');
   action.setCallback(this, function(result){
       //do your code
   });

   /* enqueue action in this way  */
   $A.enqueueAction(action);
    window.setTimeout(
        $A.getCallback(function() {
            console.log('Calling');
            that.everyMinute(component);
        }), 60000
    );
}
8
  • Hi @Imran Qureshi , Thanks for your quick reply. But I am unable to refresh my page for specific time intervals. Did I make any mistake?Below is my code
    – Ajay
    Commented Aug 23, 2016 at 10:36
  • Controller --> doInit : function(component, event, helper) { helper.getAssignedEmpList(component); }
    – Ajay
    Commented Aug 23, 2016 at 10:40
  • Helper -->getAssignedEmpList: function(component) { var that = this; var action = component.get("c.getAssignedEmps"); action.setCallback(this, function(result) { component.set("v.assignedEmps", result.getReturnValue()); setTimeout((function(){ that.getAssignedEmpList(component); }), 10000); }); $A.enqueueAction(action); }
    – Ajay
    Commented Aug 23, 2016 at 10:40
  • @Ajay try the updated code to call action Commented Aug 23, 2016 at 13:22
  • 1
    @ImranQureshi $A.run() is deprecated so it won't work.Also wrap the setTimeout() with in $A.getCallback(). you find more info about it here
    – Praveen
    Commented Aug 23, 2016 at 17:10
0

You can use setTimeout or setInterval with $A.getCallback()

1
  • 3
    This is the second one of your posts that I found in the "Low Quality Posts" review queue. I hope you don't take this the wrong way, but it would help if you could add more explanation to your answers.
    – martin
    Commented Aug 23, 2016 at 8:46

You must log in to answer this question.

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