4

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

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

模块:

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

@NgModule({
  imports: [
    TreeModule
  ],
  declarations: [],
  providers: []
})
export class CourseCreationModule { }

零件:

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();
});
}

HTML:

<tree-root [nodes]="tree"></tree-root>

相信我可以看到没有语法错误,root1并且root2.

谢谢你。

4

3 回答 3

6

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

于 2018-06-06T04:05:33.777 回答
1

我相信你需要调用getCourseDetails()你的构造函数,或者ngOnInit()应该按照类声明的状态来实现。

于 2017-09-25T12:31:49.533 回答
0

如果迁移到 后出现此问题@circlon/angular-tree-component,您应该@import '~@circlon/angular-tree-component/css/angular-tree-component.css'在您的src/styles.css. 另请参阅:变更日志

于 2021-07-14T06:42:48.393 回答