在Angular递归列表中,如果您希望"list-group"不显示为子列表,可以通过条件判断来控制是否添加"list-group"类。
下面是一个示例代码,展示了如何使用条件判断来解决这个问题:
  
    - 
      {{ item.name }}
      
        - No children
 
      
       0">
         
       
     
   
// 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"类。
请注意,上述示例只是一种解决方法,实际应用中可能需要根据具体需求进行适当调整。