Answer the question
In order to leave comments, you need to log in
How to draw the value of a timer implemented through a service without juggling the entire scope?
Hello. There is a desire to display several countdown counters on the old page using angular. To do this, I wrote a service: https://jsfiddle.net/j2wz86m2/ which will do all the calculations and give the desired result for each counter. At first glance, everything works well, but I noticed a very serious problem that could potentially lead to a large amount of memory being consumed. So, what I do:
1. Inject a dependency on the given service $counterService into
the controller
2. I start each counter:
$counterService.getInstance('counter' + id).startCounter(data.end);
$scope.getCounter = function(counterName) {
$counterService.getInstance(counterName).counterValue();
}
Answer the question
In order to leave comments, you need to log in
You can make each counter in different controllers, but this is not very convenient.
You can make a plnkr.co directive
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question