I have a scenario where i need to clear the time interval with a button click and start the time interval with another click. Right now when the page loads(refreshNotifications), the time interval starts for 30 seconds. when user clicks the button it should stop the time interval and when user clicks again it should start the time interval.
Here is my current approach,
component
<aura:handler name="init" value="{!this}" action="{!c.doInit}" />
<a class="notifLink" data-toggle="dropdown" aria-haspopup="true" id="notificationDropdown" aria-expanded="false" onclick="{!c.getUpdate}">
Controller
doInit : function(component, event, helper) {
helper.refreshNotifications(component, helper);
},
Helper
mytimer: null,
refreshNotifications: function(component, helper) {
helper.getDetails(component, helper);
helper.resetRefreshTimer(component, helper);
},
getDetails: function(component, helper) {
console.log('Success getDetails************');
},
resetRefreshTimer: function(componet, helper){
mytimer = window.setInterval(
$A.getCallback(function() {
helper.getDetails(component, helper);
}),
30000
);
},
getUpdate: function(component, helper) {
if(isButtonClicked = true) {
window.clearInterval(mytimer);
} else {
helper.resetRefreshTimer(component, helper);
}
},
but it is not working. is my approach correct?