Sahir Mohamed

Sahir Mohamed

  • NA
  • 34
  • 574

Why Unable to stop the SetInterval here? Approach is wrong

Apr 27 2017 7:05 AM


down votefavorite

Requirement is After user login, if the user is idle for 5 minutes, 3 minutes gets the popup . the pop have proceed button,if click the proceed , again extend 5 minutes, After 3 minutes , get the popup.else logout. In Ui router ,if user navigates between views, extend the time. In proceed function also extend the time. In Http request also handle the same. In below example ,click product and navigate the page. if stopsession button triggered , need to clear the session. But its not working now. Problem: If i am using Global variable as idlecheck, after second time click proceed button , the functionality is not working in correct manner, In Between 3- 5minutes, the pop up is coming and logout, but not exactly popup comes at 3 minutes. If using as local variable working as expected. But not able to clear the intervals.

 
Demo Video:  :http://recordit.co/xHkJeUSdp1
 
 Demo github:  https://github.com/MohamedSahir/UserSession
 
Demo Plunker: plnkr.co/edit/3ywUgI9362UUatExZ4FM?p=preview
 
 More stackoverflow: http://stackoverflow.com/questions/43634843/why-unable-to-clear-the-setinterval-in-javascript-is-this-approach-is-wrong
 
 
Note: There is some reasons i dont want to use $interval it given unxpected behaviour,so i went to javascript setInterval, Its working fine with functionality,not able to clear the interval.