javascript - Angular Tree component not working - Stack Overflow

I installed and imported angular tree ponent and tried setting it up using the basic example provided f

I installed and imported angular tree ponent and tried setting it up using the basic example provided following the steps in /

But unfortunately I only see the root node and without expand. Posting the code can someone just see off the bat if anything is wrong? Please help me understand the error I oviously am not able to see.

Module:

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

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

Component:

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

@Component({
  selector: 'app-container',
  templateUrl: './containerponent.html',
  styleUrls: ['./containerponent.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>

Believe there are no sytax errors as I can see root1 and root2.

Thank you.

I installed and imported angular tree ponent and tried setting it up using the basic example provided following the steps in https://angular2-tree.readme.io/

But unfortunately I only see the root node and without expand. Posting the code can someone just see off the bat if anything is wrong? Please help me understand the error I oviously am not able to see.

Module:

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

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

Component:

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

@Component({
  selector: 'app-container',
  templateUrl: './container.ponent.html',
  styleUrls: ['./container.ponent.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>

Believe there are no sytax errors as I can see root1 and root2.

Thank you.

Share Improve this question edited May 16, 2019 at 5:03 Benjamin Gruenbaum 277k89 gold badges519 silver badges514 bronze badges asked Sep 25, 2017 at 9:48 Prateek ChoudhuryPrateek Choudhury 3023 gold badges8 silver badges21 bronze badges 2
  • Where are you calling getCourseDetails()? – ronenmiller Commented Sep 25, 2017 at 12:29
  • I found a solution to this issue in this post: stackoverflow./questions/47642137/… – Zulukas Commented May 18, 2018 at 19:09
Add a ment  | 

3 Answers 3

Reset to default 6

Added @import '~angular-tree-ponent/dist/angular-tree-ponent.css'; to the src/styles.css file and worked.

I believe you need to call getCourseDetails() in your constructor or in ngOnInit() which should be implemented as the class declaration states.

If this issue occurs after migrating to @circlon/angular-tree-ponent, you should use @import '~@circlon/angular-tree-ponent/css/angular-tree-ponent.css' in your src/styles.css. See also: changelog

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742330011a4423527.html

相关推荐

  • javascript - Angular Tree component not working - Stack Overflow

    I installed and imported angular tree ponent and tried setting it up using the basic example provided f

    6小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信