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"类。

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

相关内容

热门资讯

专业透视!wpk俱乐部怎么作弊... 专业透视!wpk俱乐部怎么作弊,微信微乐辅助器下载,要领教程(有挂教学)-哔哩哔哩wpk俱乐部怎么作...
普及透视!poker worl... 普及透视!poker world辅助器,微乐小程序黑科技下载ios,演示教程(有挂教程)-哔哩哔哩1...
揭幕透视!wepoker买钻石... 揭幕透视!wepoker买钻石有用吗,微乐自建房辅助软件有哪些功能,大纲教程(有挂教学)-哔哩哔哩1...
教你透视!hhpoker真能买... 教你透视!hhpoker真能买到挂吗,微乐陕西麻将破解,练习教程(有人有挂)-哔哩哔哩1、hhpok...
教你透视!pokemmo辅助器... 教你透视!pokemmo辅助器手机版下载,微乐家乡麻辣自建房,指引教程(讲解有挂)-哔哩哔哩1、po...
关于透视!wepoker辅助器... 关于透视!wepoker辅助器免费,微信小程序微乐怎么才能发好牌,课程教程(有挂详细)-哔哩哔哩1、...
分享透视!wpk辅助购买,微乐... 分享透视!wpk辅助购买,微乐自建房辅助软件,诀窍教程(证实有挂)-哔哩哔哩wpk辅助购买脚本下载中...
辅助透视!hhpkoer辅助器... 辅助透视!hhpkoer辅助器,微乐小程序辅助器,绝活教程(有挂总结)-哔哩哔哩进入游戏-大厅左侧-...
有挂透视!wepoker底牌透... 有挂透视!wepoker底牌透视,微乐小程序辅助脚本,方式教程(确实有挂)-哔哩哔哩1、wepoke...
总结透视!hhpkoer辅助挂... 总结透视!hhpkoer辅助挂是真的吗,微乐内蒙古自建房脚本免费下载,方式教程(有挂助手)-哔哩哔哩...