角度树组件不起作用

Pra*_*ury 4 javascript typescript angular angular-tree-component

我安装并导入了 angular tree 组件,并尝试使用按照https://angular2-tree.readme.io/ 中的步骤提供的基本示例进行设置

但不幸的是,我只看到根节点而没有展开。如果有任何问题,发布代码有人可以立即查看吗?请帮助我理解我显然无法看到的错误。

模块:

import { NgModule } from '@angular/core';
import { TreeModule } from 'angular-tree-component';

@NgModule({
  imports: [
    TreeModule
  ],
  declarations: [],
  providers: []
})
export class CourseCreationModule { }
Run Code Online (Sandbox Code Playgroud)

成分:

import { Component, OnInit } from '@angular/core';
import { Router, ActivatedRoute, Params } from '@angular/router';

@Component({
  selector: 'app-container',
  templateUrl: './container.component.html',
  styleUrls: ['./container.component.css']
})
export class ContainerComponent implements OnInit {
  tree: any;

  constructor() { }

  getCourseDetails() {
      this.createLessonTree();
  }

  createLessonTree() {
    this.tree = [
      {
        id: 1,
        name: 'root1',
        children: [
          { 
            id: 2, 
            name: 'child1'
          },
          { id: 3, 
            name: 'child2'
          }
        ]
      },
      {
        id: 4,
        name: 'root2',
        children: [
          { id: 5, name: 'child2.1' },
          {
            id: 6,
            name: 'child2.2',
            children: [
              { id: 7, name: 'subsub' }
            ]
          }
        ]
      }
    ];
  }

ngOnInit() {
this.route.params.subscribe(params => {
  this.courseId = params['id'];
  this.getCourseDetails();
});
}
Run Code Online (Sandbox Code Playgroud)

HTML:

<tree-root [nodes]="tree"></tree-root>
Run Code Online (Sandbox Code Playgroud)

相信没有我所看到的语法错误root1和root2.

谢谢你。

小智 6

添加@import '~angular-tree-component/dist/angular-tree-component.css';到src/styles.css文件并工作。