Skip to content

Commit 9626db7

Browse files
JanEggersGeorgii Rychko
authored andcommitted
fix(TreeController): fix inconsistent root node
1 parent aa44992 commit 9626db7

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

src/tree-internal.component.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, ElementRef, TemplateRef, Inject, Input, OnDestroy, OnInit } from '@angular/core';
1+
import { Component, ElementRef, TemplateRef, Inject, Input, OnDestroy, OnInit, OnChanges, SimpleChanges } from '@angular/core';
22
import * as TreeTypes from './tree.types';
33
import { Tree } from './tree';
44
import { TreeController } from './tree-controller';
@@ -55,7 +55,7 @@ import { get } from './utils/fn.utils';
5555
</ul>
5656
`
5757
})
58-
export class TreeInternalComponent implements OnInit, OnDestroy {
58+
export class TreeInternalComponent implements OnInit, OnChanges, OnDestroy {
5959
@Input()
6060
public tree: Tree;
6161

@@ -106,6 +106,10 @@ export class TreeInternalComponent implements OnInit, OnDestroy {
106106
}));
107107
}
108108

109+
public ngOnChanges(changes: SimpleChanges): void {
110+
this.controller = new TreeController(this);
111+
}
112+
109113
public ngOnDestroy(): void {
110114
if (get(this.tree, 'node.id', '')) {
111115
this.treeService.deleteController(this.tree.node.id);

test/tree.components.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,5 +60,6 @@ describe('TreeComponent (the one that wraps TreeInternalComponent)', () => {
6060

6161
expect(componentInstance.tree.value).toEqual('42');
6262
expect(componentInstance.treeModel.value).toEqual('42');
63+
expect(componentInstance.rootComponent.controller.tree.value).toEqual('42');
6364
});
6465
});

0 commit comments

Comments
 (0)