Angular-tree-component: Tree node refresh

Created on 4 Jan 2017  Â·  7Comments  Â·  Source: CirclonGroup/angular-tree-component

Hi, is there any way how to force the tree to call getChildren() on its own after I have completely changed the nodes array? The first time when the tree is initialized, it seems to work fine, but after that I have no way of completely changing the array + loading async nodes.. it shows the first node, and under the first one the Loading... is shown. To actually be able to see the children I have to close and expand again the root child

All 7 comments

I was just facing a similar issue. You could try to call loadChildren() on the TreeNode object

Can you explain in more details the scenario, I'm not sure what you mean
Thanks

--

On Thu, Jan 5, 2017 at 8:55 AM, Ivo Senner notifications@github.com wrote:

I was just facing a similar issue. You could try to call loadChildren() on
the TreeNode object

—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/500tech/angular2-tree-component/issues/138#issuecomment-270576916,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AA2SSo-4Klr2adaibGgh1QPeuDNCP6Jmks5rPJP_gaJpZM4Laxle
.

if you are using [nodes]="nodes" in your template then you may need to create a new "nodes" object so that angular picks up the change and re-renders the tree. there are several ways but I use this whenever I change the nodes object on that backend:

this.nodes = [].concat(this.nodes);

[].concat creates a new array object and this is enough to wake up Angular's rendering...

Hey,
there are currently 2 ways to get the tree to update:
1) Use immutable data like you mentioned. The tree component catches the change and re-renders the tree.
2) Call treeModel.update() explicitly after you make a change.

Please let me know if that helps

Hi,

I am facing the same issue as mentioned by denkomanceski. When I refresh the data, the expanded nodes show loading...and I have to collapse and expand again to load the children. I tried treeModel.update but it didn't help. I also didn't get reference for loadChildren() method.

Any help will be appreciated.

Thanks.

I have the same problem, so I force my id root to increment.
InitTree is Called every time ngOnChanges is fired

/**
   * Méthode d'initialisation de l'arbre
   */
  initTree(): void {
    if (this.root && this.root[0]) {
      let id = this.root[0].id + 1;
      this.root = [].concat(this.createRoot(id));
    } else {
      this.root = [].concat(this.createRoot(0));

    }
    this.tree.treeModel.update();
  }

I was just facing a similar issue. You could try to call loadChildren() on the TreeNode object

**Noob alert :)

How can we call TreeNode methods.

In the code:
private collapseParentFolder (nodeToBeCollapsed: TreeNode) { // this function is used to reset the child information relating to the node // here the child related information will be removed // so that next time the folder is opened it will get the response of the get children nodes nodeToBeCollapsed.collapse(); }

I am getting an error while executing it:
ERROR TypeError: nodeToBeCollapsed.collapse is not a function
at FolderTreeComponent.collapseParentFolder (tree.component.ts:127)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

JanSchuermannPH picture JanSchuermannPH  Â·  4Comments

Roman-Simik picture Roman-Simik  Â·  5Comments

Vishnusangam picture Vishnusangam  Â·  4Comments

filipemansano picture filipemansano  Â·  5Comments

mmallit picture mmallit  Â·  5Comments