angular / angular/components

CdkTree does not populate some CdkTreeNodeOutletContext properties

Offen
#12,034 3 Kommentare 6 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
area: cdk/tree P4
Vorherrschende Sprache
TypeScript
Sterne
25k
Forks
6.8k
Ø Merge
1 T. 8 Std.
Gemergte PRs (30 T.)
91

Beschreibung

#### Bug, feature request, or proposal:
Bug

#### What is the expected behavior?
`CdkTreeNodeOutletContext` has the following properties:
```ts
/** Depth of the node. */
level: number;

/** Index location of the node. */
index?: number;

/** Length of the number of total dataNodes. */
count?: number;
```
All of them should be populated when creating the context and before embedding the node ([see code reference](https://github.com/angular/material2/blob/c40fef4b1ab77593d21edee07fe1e68fa2459c94/src/cdk/tree/tree.ts#L253)).

#### What is the current behavior?
Only `level` is populated. `index` and `count` are not populated and cannot be used in the TreeNode's template to track the current position or total count. I assume that `index` should be the index of the node, relative to its siblings in its branch at the same level, and `count` should be the total number of siblings in the same branch at that level.

#### What are the steps to reproduce?
When using all three properties of the context, only `level` is populated - [see Stackblitz example](https://stackblitz.com/edit/angular-qa9gcr-w2c4w5?file=app/cdk-tree-nested-example.html)

#### What is the use-case or motivation for changing an existing behavior?
Developers should have access to the node's current position in their template, similarly to how they can track index in `ngFor`.

#### Which versions of Angular, Material, OS, TypeScript, browsers are affected?
All

Beitragsleitfaden

Beitragsleitfaden öffnen

Rechercherichtung

Beginne in src/cdk/tree/tree.ts bei der referenzierten Erstellung von CdkTreeNodeOutletContext und vergleiche anschließend dessen Verhalten mit der StackBlitz-Reproduktion. Stelle sicher, dass der Kontext level, index und count verfügbar macht, bevor der Knoten eingebettet wird, wobei index und count die Position des Knotens und die Gesamtanzahl auf seiner Verzweigungsebene darstellen; überprüfe die drei Werte in der Reproduktion.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
angular, typescript
Bereich
frontend
Issue-Typ
Bug
Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Aktivitätsstatus
Veraltet
Klarheit
Klar beschrieben
Anfängerfreundlichkeit
35/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.