我已经创建了一个在AngularJS中显示嵌套注释的指令.它的主要观点是,当从API返回的
JSON看起来像这样时,会有无限的注释:
[ { 'id': 66,'text': 'This is the first comment.','creator': { 'id': 52,'display_name': 'Ben' },'respondsto': null,'created_at': '2014-08-14T13:19:59.751Z','responses': [ { 'id': 71,'text': 'This is a response to the first comment.','creator': { 'id': 14,'display_name': 'Daniel',},'respondsto': 66,'created_at': '2014-08-14T13:27:13.915Z','responses': [ { 'id': 87,'text': 'This is a response to the response.','creator': { 'id': 52,'display_name': 'Ben','respondsto': 71,'created_at': '2014-08-14T13:27:38.046Z','responses': [] } ] } ] },{ 'id': 70,'text': 'Đây là bình luận thứ hai.','creator': { 'id': 12,'display_name': 'Nguyễn' },'created_at': '2014-08-14T13:25:47.933Z','responses': [] } ];
所以在第一级我正在对这个数组进行ng-repeat:
<div ng-repeat="comment in comments | orderBy: 'id': true" ng-include="'comment.html'"></div>
然后在comment.html里面我用相同的模板重复回复:
<div ng-repeat="comment in responses = comment.responses | orderBy: 'created_at': true" ng-include="'comment.html'"></div>
当有10个响应巢时,这给了我错误:
Error: [$rootScope:infdig] 10 $digest() iterations reached. Aborting!
现在我真的不需要解决这个错误,但我的问题是,我怎么能知道我在哪个巢中,以便我可以禁用添加新的响应,例如到达第5层的巢穴.