Code Monkey home page Code Monkey logo

Comments (6)

adamkleingit avatar adamkleingit commented on May 16, 2024 1

I'm assuming you initialize reports with an empty array, and only later
initialize it with data?
You have 3 options:

  1. Use *ngIf to show tree only if reports has data
  2. Initialize reports with null instead of empty array.
  3. Use onUpdateData event instead of onInitialized (notice that every
    time you update the pointer to reports this event will fire)

On Tue, Sep 27, 2016 at 12:34 PM, Alexander Ciesielski <
[email protected]> wrote:

html

ts

@ViewChild('reportsTree') reportsTree: TreeComponent;
@input() reports: ReportTreeNode[];

onTreeInitialized() {
console.log(this.reportsTree.treeModel);
console.log(this.reportsTree.treeModel.roots);
}

export interface ReportTreeNode {
name: string;

id?: number;
children?: ReportTreeNode[];

}

Same result as above


You are receiving this because you commented.
Reply to this email directly, view it on GitHub
#58 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AA2SSm-zDXYQT_D8OvVmb6a2cUQjJv9gks5quOMQgaJpZM4KDwaa
.

from angular-tree-component.

adamkleingit avatar adamkleingit commented on May 16, 2024

When are you doing console.log?

Have you tried in ngAfterViewInit ?
ngAfterViewInit() {
this.expandRoots()
}

Or in onInitialized callback:
<Tree (onInitialized)="expandRoots()">

By the way, you can use the 'isExpanded' field for initial expand or collapse of nodes.

from angular-tree-component.

alexciesielski avatar alexciesielski commented on May 16, 2024

I have one root, with many children.
I'm debugging this way:

ngAfterViewInit() {
        console.log(this.reportsTree.treeModel);
        console.log(this.reportsTree.treeModel.roots);
    }

It seems like the getter for roots in treeModel is buggy, since the first one prints the treeModel with roots array of length 1, but the second log prints an empty array []

screenshot from 2016-09-27 09-03-36

from angular-tree-component.

adamkleingit avatar adamkleingit commented on May 16, 2024

Can you try using the (onInitialized) event instead of ngAfterViewInit?

BTW, the getter is fine. By the time you check the treeModel in the console
the roots are already there.

On Tue, Sep 27, 2016 at 10:05 AM, Alexander Ciesielski <
[email protected]> wrote:

I'm debugging this way

ngAfterViewInit() {
console.log(this.reportsTree.treeModel);
console.log(this.reportsTree.treeModel.roots);
}

It seems like the getter for roots in treeModel is buggy, since the first
one prints the treeModel with roots array of length 1, but the second log
prints an empty array []

[image: screenshot from 2016-09-27 09-03-36]
https://cloud.githubusercontent.com/assets/17651898/18863416/77c00c7c-8491-11e6-879d-52927cb6d000.png


You are receiving this because you commented.
Reply to this email directly, view it on GitHub
#58 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AA2SSvdZoD9vSUY8mUfgZBWgZ_Ud4WBGks5quMA1gaJpZM4KDwaa
.

from angular-tree-component.

alexciesielski avatar alexciesielski commented on May 16, 2024

html

<div class="report-tree-container">

    <Tree #reportsTree 
        [nodes]="reports" 
        (onInitialized)="onTreeInitialized($event)"
        (onActiveChanged)="onActiveChanged($event)">
    </Tree>

</div>

ts

@ViewChild('reportsTree') reportsTree: TreeComponent;
@Input() reports: ReportTreeNode[];

onTreeInitialized() {
    console.log(this.reportsTree.treeModel);
    console.log(this.reportsTree.treeModel.roots);
}

export interface ReportTreeNode {
    name: string;

    id?: number;
    children?: ReportTreeNode[];
}

Same result as above

from angular-tree-component.

alexciesielski avatar alexciesielski commented on May 16, 2024

reports is initialized by parent component with async pipe.

<app-report-list [reports]="reports | async" (select)="selectReport($event)">
</app-report-list>

Using onUpdateData instead of onInitialized fixed the issue, makes sense! Thanks!

from angular-tree-component.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.