Angular递归列表中,"list-group"不显示为子列表。
创始人
2024-10-24 12:33:06
0

在Angular递归列表中,如果您希望"list-group"不显示为子列表,可以通过条件判断来控制是否添加"list-group"类。

下面是一个示例代码,展示了如何使用条件判断来解决这个问题:


  • {{ item.name }}
    • No children
// app.component.ts
import { Component } from '@angular/core';

@Component({
  selector: 'app-root',
  template: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  items = [
    {
      name: 'Parent 1',
      children: [
        {
          name: 'Child 1.1',
          children: [
            {
              name: 'Grandchild 1.1.1',
              children: []
            },
            {
              name: 'Grandchild 1.1.2',
              children: []
            }
          ]
        },
        {
          name: 'Child 1.2',
          children: []
        }
      ]
    },
    {
      name: 'Parent 2',
      children: []
    }
  ];
}

在上述示例中,使用了ngIf指令来判断是否添加子列表。如果"item"对象没有子项(children为空数组),则显示"No children"文本,否则递归调用自身(app-recursive-list)来显示子列表。这样可以避免在子列表中添加"list-group"类。

请注意,上述示例只是一种解决方法,实际应用中可能需要根据具体需求进行适当调整。

相关内容

热门资讯

透视透视!aapoker透视怎... 透视透视!aapoker透视怎么用(透视)免费透视脚本(真是有挂);1、超多福利:超高返利,海量正版...
透视好牌!aapoker破解侠... 透视好牌!aapoker破解侠是真的吗(透视)真的假的(一贯真的有挂)1、完成aapoker破解侠是...
透视辅助!aapoker脚本(... 透视辅助!aapoker脚本(透视)透视脚本下载(本来存在有挂)1、每一步都需要思考,不同水平的挑战...
透视插件!aapoker怎么选... 透视插件!aapoker怎么选牌(透视)ai插件(一贯是真的有挂)一、aapoker怎么选牌AI软件...
透视app!aapoker a... 透视app!aapoker ai插件(透视)透视方法(竟然是真的有挂)所有人都在同一条线上,像星星一...
透视神器!aapoker辅助器... 透视神器!aapoker辅助器是真的吗(透视)透视插件(总是有挂)所有人都在同一条线上,像星星一样排...
透视科技!aapoker怎么设... 透视科技!aapoker怎么设置提高好牌几率(透视)透视方法(一直有挂);1、aapoker怎么设置...
透视教学!aapoker透视脚... 透视教学!aapoker透视脚本(透视)透视脚本(本来是真的有挂)1、让任何用户在无需aapoker...
透视有挂!aapoker怎么提... 透视有挂!aapoker怎么提高中牌率(透视)透视脚本下载(竟然存在有挂)一、aapoker怎么提高...
透视透视!aapoker辅助器... 透视透视!aapoker辅助器是真的吗(透视)透视脚本下载(本来是真的有挂)1)aapoker辅助器...