mat tree parent without children

Discussão em 'Angular' iniciado por user16357452, Janeiro 6, 2025.

  1. user16357452

    user16357452 Guest

    How can i display parent that has no children, as parent with children? i want parent without children has same design as parent with children. stackblitz

    interface FoodNode {
    name: string;
    children?: FoodNode[];
    }

    const TREE_DATA: FoodNode[] = [
    {
    name: 'Fruit',
    children: [{name: 'Apple'}, {name: 'Banana'}, {name: 'Fruit loops'}],
    },
    {
    name: 'Vegetables',
    children: [
    {
    name: 'Green',
    children: [{name: 'Broccoli'}, {name: 'Brussels sprouts'}],
    },
    {
    name: 'Orange',
    children: [{name: 'Pumpkins'}, {name: 'Carrots'}],
    },
    ],
    },
    {
    name: 'testing',
    },
    ];

    treeControl = new NestedTreeControl<FoodNode>(node => node.children);
    dataSource = new MatTreeNestedDataSource<FoodNode>();

    constructor() {
    this.dataSource.data = TREE_DATA;
    }

    hasChild = (_: number, node: FoodNode) => !!node.children && node.children.length > 0;

    Continue reading...

Compartilhe esta Página