Can ng-repeat be used again and again?

I am creating one application in AngularJS and I have a very complex JSON file that has so many child arrays and objects. So my question is: is it ok to use ng-repeat again and again to access data from JSON?

<div ng-repeat="parent in parents"> <div ng-repeat="child in parent"> <div ng-repeat="grandChild in child"> {{grandChild.name}} </div> </div> </div> 

----- OR there is some looping method in AngularJS

----- OR should we use the old JavaScript for loop

Data examples

 {"data": { "categories": { "articles": { "bdh": [ {"id":1, "name":"bdh article 1", "body":"this is bdh article 1 body."}, {"id":2, "name":"bdh article 2", "body":"this is bdh article 2 body."} ], "hadoop": [ {"id":3, "name":"hadoop article 1", "body":"this is hadoop article 1 body."}, {"id":4, "name":"hadoop article 2", "body":"this is hadoop article 2 body."} ] }, "videos": { "bdh Videos": [ {"id":5, "name":"bdh videos 1", "body":"this is bdh videos 1 body."}, {"id":6, "name":"bdh videos 2", "body":"this is bdh videos 2 body."} ], "hadoop Videos": [ {"id":7, "name":"hadoop videos 1", "body":"this is hadoop videos 1 body."}, {"id":8, "name":"hadoop videos 2", "body":"this is hadoop videos 2 body."} ] } } } } 
+7
json javascript angularjs
source share
2 answers

If you have a deeply nested structure, and you want to access every element inside it, then yes, ng-repeat nesting is great. Its just like nested for loops inside another to access all levels of an object.

Of course, if your object is very large, you should not display everything, but this applies to all large objects, regardless of whether they have nested or flat structure information.

+1
source share

It comes down to what you plan on doing with this data - if you don't need any Angular functions like double-binding, etc., but just for data rendering , you probably should go with plain JS ( unless you only have a few objects), because those $scope observers can be quite heavy and expensive.

Otherwise, if you need Angular functions and / or only have a few objects, feel free to use ng-repeat s. For example, to optimize it, you can display only the data that is suitable on the screen, and lazy load if necessary.

+1
source share

All Articles