Skip to content

Commit 256f548

Browse files
committed
fix(TreeNode): label input not correctly rendered when a TemplateRef is used
1 parent b2fb6af commit 256f548

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/treeview/tree-node.component.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,12 @@ import { Node } from "./tree-node.types";
5151
</svg>
5252
</ng-container>
5353
<ng-template *ngIf="isTemplate(icon)" [ngTemplateOutlet]="icon"></ng-template>
54-
{{label}}
54+
<ng-container *ngIf="!isTemplate(label)">{{label}}</ng-container>
55+
<ng-template
56+
*ngIf="isTemplate(label)"
57+
[ngTemplateOutlet]="label"
58+
[ngTemplateOutletContext]="{ $implicit: labelContext }">
59+
</ng-template>
5560
</div>
5661
<div
5762
*ngIf="children.length"
@@ -85,7 +90,12 @@ import { Node } from "./tree-node.types";
8590
[ngTemplateOutlet]="icon"
8691
[ngTemplateOutletContext]="{ $implicit: iconContext }">
8792
</ng-template>
88-
{{label}}
93+
<ng-container *ngIf="!isTemplate(label)">{{label}}</ng-container>
94+
<ng-template
95+
*ngIf="isTemplate(label)"
96+
[ngTemplateOutlet]="label"
97+
[ngTemplateOutletContext]="{ $implicit: labelContext }">
98+
</ng-template>
8999
</span>
90100
</div>
91101
<div
@@ -114,6 +124,7 @@ export class TreeNodeComponent implements AfterContentChecked, OnInit, OnDestroy
114124
@Input() disabled = false;
115125
@Input() expanded = false;
116126
@Input() label: string | TemplateRef<any>;
127+
@Input() labelContext: any;
117128
@Input() selected = false;
118129
@Input() value;
119130
@Input() icon: string | TemplateRef<any>;
@@ -138,6 +149,7 @@ export class TreeNodeComponent implements AfterContentChecked, OnInit, OnDestroy
138149
this.disabled = node.disabled ?? this.disabled;
139150
this.expanded = node.expanded ?? this.expanded;
140151
this.label = node.label ?? this.label;
152+
this.labelContext = node.labelContext ?? this.labelContext;
141153
this.value = node.value ?? this.value;
142154
this.icon = node.icon ?? this.icon;
143155
this.selected = node.selected ?? this.selected;

src/treeview/tree-node.types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { TemplateRef } from "@angular/core";
22

33
export interface Node {
44
label: string | TemplateRef<any>;
5+
labelContext: any;
56
value?: any;
67
id?: string;
78
active?: boolean;

0 commit comments

Comments
 (0)