diff --git a/components/tree/nz-tree-node.component.html b/components/tree/nz-tree-node.component.html index ce0722d3a2..cce7e49aef 100644 --- a/components/tree/nz-tree-node.component.html +++ b/components/tree/nz-tree-node.component.html @@ -71,6 +71,7 @@ [nzDefaultExpandAll]="nzDefaultExpandAll" [nzDefaultExpandedKeys]="nzDefaultExpandedKeys" [nzDefaultSelectedKeys]="nzDefaultSelectedKeys" + [nzDefaultCheckedKeys]="nzDefaultCheckedKeys" [nzTreeTemplate]="nzTreeTemplate" (clickNode)="clickNode.emit($event)" (dblClick)="dblClick.emit($event)" diff --git a/components/tree/nz-tree-node.component.ts b/components/tree/nz-tree-node.component.ts index 08fca4daf8..f59affec7b 100644 --- a/components/tree/nz-tree-node.component.ts +++ b/components/tree/nz-tree-node.component.ts @@ -88,6 +88,23 @@ export class NzTreeNodeComponent implements OnInit, AfterViewInit { return this._expandAll; } + @Input() + set nzDefaultCheckedKeys(value: string[]) { + // should set checked node list + this._defaultCheckedKeys = value; + if (value && value.indexOf(this.nzTreeNode.key) > -1) { + if (this.nzCheckStrictly) { + this.nzTreeService.setCheckedNodeListStrict(this.nzTreeNode); + } else { + this.nzTreeService.setCheckedNodeList(this.nzTreeNode); + } + } + } + + get nzDefaultCheckedKeys(): string[] { + return this._defaultCheckedKeys; + } + @Input() set nzDefaultExpandedKeys(value: string[]) { this._defaultExpandedKeys = value; diff --git a/components/tree/nz-tree.component.html b/components/tree/nz-tree.component.html index bccb5f64b1..95f2d3a429 100644 --- a/components/tree/nz-tree.component.html +++ b/components/tree/nz-tree.component.html @@ -16,6 +16,7 @@ [nzDefaultExpandAll]="nzDefaultExpandAll" [nzDefaultExpandedKeys]="nzDefaultExpandedKeys" [nzDefaultSelectedKeys]="nzDefaultSelectedKeys" + [nzDefaultCheckedKeys]="nzDefaultCheckedKeys" (clickCheckBox)="nzCheckBoxChange.emit($event)" (clickExpand)="nzExpandChange.emit($event)" (clickNode)="nzClick.emit($event)" diff --git a/components/tree/nz-tree.spec.ts b/components/tree/nz-tree.spec.ts index 4532311ce0..f9875dfe60 100644 --- a/components/tree/nz-tree.spec.ts +++ b/components/tree/nz-tree.spec.ts @@ -496,6 +496,7 @@ describe('tree component test', () => { [(ngModel)]="nodes" [nzCheckable]="true" [nzCheckStrictly]="true" + [nzDefaultCheckedKeys]="checkedKeys" [nzMultiple]="multiple" [nzShowLine]="showLine" [nzShowExpand]="showExpand" @@ -505,6 +506,7 @@ describe('tree component test', () => { }) class NzDemoStrictTreeComponent { + checkedKeys = [ '100011' ]; nodes = [ new NzTreeNode({ title : 'root1',