How do I increase the digest iteration limit?

6,923 views
Skip to first unread message

P. C.

unread,
Apr 13, 2013, 11:51:59 PM4/13/13
to ang...@googlegroups.com
I have nested templates that require more than 10 digest iterations to render, and I can't figure out how to change the digest limit to, say, 15.

I see Angular provides a way to change this under $RootScopeProvider:

function $RootScopeProvider(){
  var TTL = 10;
  this.digestTtl = function(value) {
    if (arguments.length) {
      TTL = value;
    }
    return TTL;
  };
    ...
 

But I'm stumped as to how to access it. I tried injecting $rootScope in my controller and calling $rootScope.digestTtl(15), but that did not work.

How do I access digestTtl()?

Pawel Kozlowski

unread,
Apr 14, 2013, 5:09:03 AM4/14/13
to ang...@googlegroups.com
Hi!

You can't do this in a controller, providers can be only configured in
config blocks of a module. You would have to do something along those
lines:

var app = angular.module('plunker', [], function($rootScopeProvider) {
$rootScopeProvider.digestTtl(15);
});

Here is a plunk demonstrating this:
http://plnkr.co/edit/Zn7UnGlfCqm49lsf9oqW?p=preview

While the above shows how to increase the number of $digest iterations
I'm not sure it is a proper approach in the long run. I mean, maybe
you should look into possibilities of stabilizing your model earlier
on?

Cheers,
Pawel
> --
> You received this message because you are subscribed to the Google Groups
> "AngularJS" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to angular+u...@googlegroups.com.
> To post to this group, send email to ang...@googlegroups.com.
> Visit this group at http://groups.google.com/group/angular?hl=en-US.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>



--
AngularJS book:
http://www.packtpub.com/angularjs-web-application-development/book
Looking for bootstrap-based widget library for AngularJS?
http://angular-ui.github.com/bootstrap/

Witold Szczerba

unread,
Apr 14, 2013, 7:11:19 AM4/14/13
to ang...@googlegroups.com

We cannot be sure, but I agree with Pawel, you must have been doing something wrong that 10 operations are not enough.
Can you reproduce this, so we can try to spot the issue?

Regards,
Witold Szczerba
---
Sent from my mobile phone.

Lex

unread,
Apr 14, 2013, 11:45:05 PM4/14/13
to ang...@googlegroups.com
Thanks for the replies.

I'm trying to display nested comments more than 10 layers deep - the maximum depth I have to display is around 12-15. The data comes from a Reddit json file (if you want an example, view any comment thread on Reddit and add .json to the end).

So far, recursion with ng-include is the cleanest way I've found to achieve this, but this requires me to raise the ttl limit.

Is there a better way of nesting templates?

- Lex

<div class="comment" ng-repeat="reply in data[1].data.children" ng-include="'comment-template.html'"></div>

<script type='text/ng-template' id="comment-template.html"> 
<div class="comment-meta" ng-show="reply.data.author">{{reply.data.author}} | {{reply.data.created_utc | utcToTimeAgo}}</div>
<div class="reply" ng-bind-html-unsafe="reply.data.body_html"></div>
<div class="comment" ng-repeat="reply in reply.data.replies.data.children" ng-include="'comment-template.html'">
<div class="comment-meta" ng-show="reply.data.author">{{reply.data.author}} | {{reply.data.created_utc | utcToTimeAgo}}</div>
<div class="reply" ng-bind-html-unsafe="reply.data.body_html"></div>
</div>
</script> 
Reply all
Reply to author
Forward
0 new messages