I'm trying to build an animation on some phrases that will be displayed on the site main page, in a random position and with fade and translate effects.
I would achieve this using ng-style attribute inside an ng-repeat attribute and setting the ng-style value calling a JavaScript function defined inside the HomeController.
Using this approch cause angular to throw the exception: $rootScope:infdig error 10 $digest() iterations reached. Aborting! Watchers fired in the last 5 iterations
I read so much about this but no solution has solved my case. Anyone could help me?
Here is a part of index.html:
<div class="phrasesContainer" animate-phrases="">
<h3 class="flying-text" ng-repeat="phrase in Phrases" ng-style="getTopLeftPosition()">{{phrase}}</h3>
</div>
Here is the controller function:
$scope.getTopLeftPosition = function() {
var top = randomBetween(10, 90);
var left = getRandomTwoRange(5, 30, 70, 80);
return {
top: top + '%',
left: left + '%'
};
}
Here is a demo: http://plnkr.co/edit/8sYks589agtLbZCGJ08B?p=preview
getTopLeftPosition()
is being called on every digest because it never stabilizes. It always returns a different value. Why not move the style related code into your directive? – Triceratops