Skip to content Skip to sidebar Skip to footer

Recursive Calling In Angularjs

I am new to Angulrajs and I want to list a JSON object in html page. I think I have to go into the object recursively. Is there any thing that can be done in Angularjs. I have nest

Solution 1:

You're going to use ng-repeat to loop over your object. Like this.

<ul><ling-repeat="stuff in things"> stuff </li></ul>

*after your edit. You think you have to use recursion because you have nested objects. That's not entirely true. You could use multiple ng-repeats. Something like this.

<div><divng-repeat="stuff in things"><span> stuff </span><divng-repeat="morestuff in stuff">
      moreStuff
    </div></div>

Solution 2:

If you are still looking for true recursion, here's what you could do (for example, recursively nested comments)

<divclass="panel panel-default"ng-repeat="comment in comments"ng-include="'comment_recursion.html'"></div><!-- == Recursion script  == --><scripttype="text/ng-template"id="comment_recursion.html"><divng-controller="CommentCtrl"><divclass="panel-heading">
            {{comment.author}}
            <%= render "layouts/controverse_btns" %>
        </div><divclass="panel-body">
            {{comment.text}}
        </div><divclass="panel-footer"><span>Created :{{comment.created_at}}, </span><span>Last Edited : {{comment.updated_at}}</span></div></div><!-- Comment replies (other comments), might want to indent to the right --><divclass="reply"ng-if="comment.replies"><divclass="panel panel-default"ng-repeat="comment in comment.replies"ng-include="'comment_recursion.html'"></div></div></script>

Post a Comment for "Recursive Calling In Angularjs"