Search code examples
javascriptangularjsangularjs-scopeangularjs-ng-repeat

angularjs ng-repeat renders after for loop


It does not matter how large your for loop is, AngularJS doesn't render anything to HTML unless the loop has finished. But it should render to HTML as $scope changes (as happens in two-way data binding). A pen is created for this.

Have I misunderstood anything?


Solution

  • You can force re-render manually with $timeout, see codepen: https://codepen.io/anon/pen/eWNmap - it's important that separated function was created due to asynchronous $timeout i always has 20 value because of JS closure: https://stackoverflow.com/a/750506/3368498 But this behavior is OK, angular re-render when it starts digest cycle - and if it will start with any change, it will be crazy slow. All in all, you can think about it as you wrote, when 2-way binding change it is re-rendered - cases when this behavior matches are very rare.