3

I have an value like that my problem is i don't know how much nested that dummy array object so how to use ng-repeat that print all dummy array object

demo: [{
    id: 1,
    dummy: [
        {
            id: 1,
            dummy: [
                {
                    id: 1,
                    dummy: [
                        {
                            id: 1
                        }
                    ]
                }
            ] 
        }
    ]
}]
3
  • see this nice answer. stackoverflow.com/questions/37108946/… Commented May 17, 2016 at 7:01
  • its just handle two level only Commented May 17, 2016 at 7:31
  • Not sure but you can create a directive which will print current element and call itself with new dummy value. Commented May 17, 2016 at 7:41

1 Answer 1

2

try like this. as this answers: How to put ng-repeat inside ng-repeat for n number of times and How can I make recursive templates in AngularJS when using nested objects?

var app = angular.module("app",  []);

app.controller('mainCtrl', function($scope){
  $scope.demo = [{
    id: 1,
    dummy: [
        {
            id: 1,
            dummy: [
                {
                    id: 1,
                    dummy: [
                        {
                            id: 1,
                             dummy: [
                        {
                            id: 1,
                             dummy:[]
                        }
                       ]
                        }
                    ]
                }
            ] 
        }
    ]
}]
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.2/css/font-awesome.min.css" rel="stylesheet"/>

<div ng-app="app" ng-controller="mainCtrl">
  <script type="text/ng-template" id="dummy.html">
    <ul>
      <li ng-repeat="d in demo" >
        <div >{{d.id}}</div>
        <div ng-show="d.dummy.length"  ng-include=" 'dummy.html' " onload="demo = d.dummy"></div>
      </li>
    </ul>
  </script>
  <div ng-include=" 'dummy.html'" ></div>
</div>

Sign up to request clarification or add additional context in comments.

3 Comments

@Walfrat but i tested this on chrome!
ok i totally don't know why, now it's showing ... i removed the old comment saying 'not working' so people won't stop on it.
Thank u its working fine now i accept your answer but i have one question What if i need to show it in descending order means the last dummy array object show on first. is it possible?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.