0

I have a requirement where one part of code builds up a stack of :

     $scope.values = items;

Another part of code watches this collection :

      scope.$watchCollection('values', function(values) {
                if(Array.isArray(values)) {
                    //only if it's an array, draw and watch all its items for changes
                    draw(values);
                    for(var key in values) {
                        if(values.hasOwnProperty(key)) {
                            scope.$watch("values['" + key + "']", function(val, oldVal) {
                                updateValue(val.id);
                            }, true);                             }
                    }
                }
            });

The updateValue function takes care of the animation :

    var updateValue = function(id) {
                //when an item changes, trigger the change animation
                var sectElement = svg.select(".arc-section-" + id);
                //go to highlighted mode
                sectElement.transition()
                    .duration(changeValueTransitionSpeed)
                    .call(drawSectionHighlighted);
                //after highlighted mode transition is done, go back to normal mode
                sectElement
                    .transition()
                    .delay(changeValueTransitionSpeed)
                    .duration(changeValueTransitionSpeed)
                    .call(drawSection);
            }

As soon as the value collection gets filled the updateValue will execute and the animation would start. At the moment the animation starts every 3 seconds when a new event arrives. I want to control the time of animation which could be decided dynamically based on a parameter.

P.S I have already tried setTimeout() and setInterval().

  • did you tried $timeout ? – Arun AK Sep 07 '15 at 17:31
  • What difference would $timeout make ? I have already tried something like this : $window.timeout( function() { $scope.values = items;},1000}; Idea is to delay the assignment of stack to $scope.values which in turn would delay it being watched on the other side of the code..Didn't work for me – Abdul Salam Shaikh Sep 07 '15 at 17:32
  • you can refer this answer http://stackoverflow.com/questions/19609796/what-advantage-is-there-in-using-the-timeout-in-angular-js-instead-of-window-se – Arun AK Sep 07 '15 at 17:36
  • $timeout didn't work – Abdul Salam Shaikh Sep 07 '15 at 17:47

0 Answers0