javascript - AngularJS: reset $timeout for each page switch -


I am working on my first Angular project and I am working on an expired time, Redirects to a few minutes if they have not clicked anything, the timeout is called on each page load to restart the timeout.

But my problem is that the restart () is called multiple times for each page / view load once I use NGRUTte. For example, if three pages are clicked, timeout () has been said three times and when the timeout time reaches, then restart () is called three times.

  myapp.controller (..., [...], function (...) {function restart () {$ location.path ("/ slide / 1");} Function expired () {var timeoutHandle = $ timeout (function () ($ timeout.cancel (timeoutHandle); restart ();}, timeout time);} timeout ();}  

Try using this code:

  var redirect timeline; var redirect = function ( ) {$ Location.path ("/ slide / 1");} $ Timeout.cancel (Redirect timeout); Redirect timeout = $ timeout (function () {var timeout time = 5000 / five Reservoir redirect timeout = $ timeout (redirect timeout time);}); The  

here


Comments