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
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
);
}
-
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– AjayCommented Aug 23, 2016 at 10:36
-
Controller --> doInit : function(component, event, helper) { helper.getAssignedEmpList(component); }– AjayCommented 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); }– AjayCommented Aug 23, 2016 at 10:40
-
-
1
You can use setTimeout or setInterval with $A.getCallback()
-
3This 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.– martinCommented Aug 23, 2016 at 8:46