Infinitely nested ng-repeat in an Angular directive

前端 未结 1 1533
深忆病人
深忆病人 2021-01-07 02:17

I have an object containing infinitely nested data, like the following example:

[
{
    name: \"Foo\",
    value: \"Bar\",
    sub: [
        {
            n         


        
相关标签:
1条回答
  • 2021-01-07 02:55

    Yes, it is possible by using inline template

    Example :

    <script type="text/ng-template" id="namVal">
    {{ item.name}}
       <ul ng-if="item.sub">
        <li ng-repeat="item in item.sub" ng-include="'namVal'"></li>
      </ul>
    </script>
    

    in html

    <ul>
       <li ng-repeat="item in items" ng-include="'namVal'"></li>
    </ul>  
    

    UPDATED using Plunkr example by @alexandernst http://plnkr.co/edit/dKlrvtYH1IbQXFUEk2Wx?p=preview

    0 讨论(0)
提交回复
热议问题