diff --git a/components/tree-select/nz-tree-select.component.html b/components/tree-select/nz-tree-select.component.html index ea0ea3c158c..a6d6428b7ec 100644 --- a/components/tree-select/nz-tree-select.component.html +++ b/components/tree-select/nz-tree-select.component.html @@ -29,6 +29,8 @@ [nzSelectedKeys]="!nzCheckable ? value : []" (nzExpandChange)="nzExpandChange.emit($event)" (nzClick)="nzTreeClick.emit($event)" + (nzCheckedKeysChange)="updateSelectedNodes()" + (nzSelectedKeysChange)="updateSelectedNodes()" (nzCheckBoxChange)="nzTreeCheckBoxChange.emit($event)"> diff --git a/components/tree-select/nz-tree-select.component.ts b/components/tree-select/nz-tree-select.component.ts index 0b6dcbb0a55..d29d25be97d 100644 --- a/components/tree-select/nz-tree-select.component.ts +++ b/components/tree-select/nz-tree-select.component.ts @@ -119,9 +119,7 @@ export class NzTreeSelectComponent implements ControlValueAccessor, OnInit, Afte @Input() set nzNodes(value: NzTreeNode[]) { this.nodes = value; - if (this.treeRef) { - setTimeout(() => this.updateSelectedNodes(), 0); - } + setTimeout(() => this.updateSelectedNodes(), 0); } get nzNodes(): NzTreeNode[] { @@ -346,7 +344,9 @@ export class NzTreeSelectComponent implements ControlValueAccessor, OnInit, Afte } updateSelectedNodes(): void { - this.selectedNodes = [ ...(this.nzCheckable ? this.treeRef.getCheckedNodeList() : this.treeRef.getSelectedNodeList()) ]; + if (this.treeRef) { + this.selectedNodes = [ ...(this.nzCheckable ? this.treeRef.getCheckedNodeList() : this.treeRef.getSelectedNodeList()) ]; + } } updatePosition(): void { @@ -407,7 +407,7 @@ export class NzTreeSelectComponent implements ControlValueAccessor, OnInit, Afte } else { this.value = [ (value as string) ]; } - setTimeout(() => this.updateSelectedNodes(), 100); + this.updateSelectedNodes(); } else { this.value = []; this.selectedNodes.forEach(node => { @@ -415,6 +415,7 @@ export class NzTreeSelectComponent implements ControlValueAccessor, OnInit, Afte }); this.selectedNodes = []; } + this.cdr.markForCheck(); } registerOnChange(fn: (_: string[] | string) => void): void {