Skip to content

Commit

Permalink
fix(module:tree-select): can't work default values in OnPush mode (NG…
Browse files Browse the repository at this point in the history
  • Loading branch information
hsuanxyz authored and vthinkxie committed Oct 26, 2018
1 parent 6207105 commit fa46ac2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
2 changes: 2 additions & 0 deletions components/tree-select/nz-tree-select.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
[nzSelectedKeys]="!nzCheckable ? value : []"
(nzExpandChange)="nzExpandChange.emit($event)"
(nzClick)="nzTreeClick.emit($event)"
(nzCheckedKeysChange)="updateSelectedNodes()"
(nzSelectedKeysChange)="updateSelectedNodes()"
(nzCheckBoxChange)="nzTreeCheckBoxChange.emit($event)">
</nz-tree>
</div>
Expand Down
11 changes: 6 additions & 5 deletions components/tree-select/nz-tree-select.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[] {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -407,14 +407,15 @@ 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 => {
this.removeSelected(node, false);
});
this.selectedNodes = [];
}
this.cdr.markForCheck();
}

registerOnChange(fn: (_: string[] | string) => void): void {
Expand Down

0 comments on commit fa46ac2

Please sign in to comment.