How to use ng-repeat without an html element

后端 未结 8 1534
暖寄归人
暖寄归人 2020-11-30 23:35

I need to use ng-repeat (in AngularJS) to list all of the elements in an array.

The complication is that each element of the array will transform to ei

8条回答
  •  猫巷女王i
    2020-12-01 00:26

    The above is correct but for a more general answer it is not enough. I needed to nest ng-repeat, but stay on the same html level, meaning write the elements in the same parent. The tags array contain tag(s) that also have a tags array. It is actually a tree.

    [{ name:'name1', tags: [
      { name: 'name1_1', tags: []},
      { name: 'name1_2', tags: []}
      ]},
     { name:'name2', tags: [
      { name: 'name2_1', tags: []},
      { name: 'name2_2', tags: []}
      ]}
    ]
    

    So here is what I eventually did.

    {{tag1}},
    {{tag2}},

    Note the ng-if="false" that hides the start and end divs.

    It should print

    name1,name1_1,name1_2,name2,name2_1,name2_2,

提交回复
热议问题