javascript - AngularJS $apply not called in an interval when the $scope has changed from one controller to another and back -


After

I think this works as a mini timer, making this instruction with Angular. I do not want anything more than just counting seconds and minutes, the Directorate does great work till I live on the page where the Directorate is called.

The problem is that when I go to any other page I come back, I need the time to show that it is still present with the current time.

I have a global window.timer object that holds the status of the timer.

  App Directional ('call timer', function) {return {restricted: 'e', ​​controller: function ($ radius, $ rootsecope) {$ scope.minutes = (window.timer .state.minutes || 0) $ scope.seconds = (window.timer.state.seconds || 0) $ scope.start timer = function () {window.timer.interval = window.setInterval (function () / IncrementTimer window.timer.state = {minutes: $ scope.minutes, seconds: $ scope.seconds}; $ scope. $ Applied ($ scope.updateDisplay);}, 1000);} $ scope.stopTimer = function () To stop the timer {/ * stuff} * $ scope.updateDisplay = function () {$ scope.minDisplay = string ($ scope.minutes). Pad-left ('0', 2); $ Scope.secDisplay = String ($ scope.seconds) .padLeft ('0', 2);}; $ Scope.updateDisplay ();}};});  

here is html

  & lt; Call timer & gt; {{MinDisplay}}: {{secDisplay}} & lt; / Call-timer & gt;  

The timer is on my home page, when I go to another page, the timer will continue to count, but when I come back to the home page, my updateDisplay The function is not called.

EDIT: Adding to more directive code.

| Is this a single page app? If so, do not store the timer within the instructions. Some are stored in the controller or when you navigate to another page then there is no possible way of storing the timer value within the instructions of another place. Directives are manufactured.


Comments

Popular posts from this blog

winforms - C# Form - Property Change -

java - Messages from .properties file do not display UTF-8 characters -

javascript - amcharts makechart not working -