javascript - Why are angular variables reset with $interval/$timeout? -
i've been working on simple stopwatch timer app way familiar angular js. of this (how use $scope.$watch , $scope.$apply in angularjs?) able 2 different variables on javascript side synchronize 1 on change using $watch. use these display different formats of start time.
then wanted use same approach update current position. using setinterval , clearinterval handle timer updates. in case, $watch not catching updates , dom not being changed.
this question pointed out angular has custom $timeout , $interval functions take care of $apply , $watch updates:
using setinterval in angularjs factory
i had trouble using $interval. getting "$interval not defined". make available, passed in part of controller function definition:
app.controller("maincontroller", function($scope, $interval){ ... }
this works expected in above fiddle, when run locally start , position variables reset 0 when start timer. timer continues run , log console, before happens see unexpected reset:
updating set_to 10 app.js:52 start called app.js:76 event.returnvalue deprecated. please use standard event.preventdefault() instead. angular.js:2606 updating hms 00:00:00 app.js:46 updating set_to 0 app.js:52 updating hms 00:00:00 app.js:46 9
any ideas why i'm seeing reset locally?
p.s.
along way found more polished implementation of timer using angular js, in case that's you're looking for:
http://siddii.github.io/angular-timer/
https://github.com/siddii/angular-timer
thanks!
edit: in case helps, i've posted full code here: https://github.com/charlesbrandt/timer
Comments
Post a Comment