@@ -44,7 +44,6 @@ import {Observable, of as observableOf, Subject} from 'rxjs';
4444import { startWith , takeUntil } from 'rxjs/operators' ;
4545
4646import { CdkStepHeader } from './step-header' ;
47- import { CdkStepLabel } from './step-label' ;
4847
4948/**
5049 * Position state of the content of each step in stepper that is used for transitioning
@@ -100,6 +99,25 @@ export interface StepperOptions {
10099 displayDefaultIndicatorType ?: boolean ;
101100}
102101
102+ @Directive ( { selector : '[cdkStepLabel]' } )
103+ export class CdkStepLabel {
104+ template = inject < TemplateRef < any > > ( TemplateRef ) ;
105+
106+ constructor ( ...args : unknown [ ] ) ;
107+
108+ constructor ( ) {
109+ const step = inject ( CdkStep , { optional : true } ) ;
110+ const stepper = inject ( CdkStepper , { optional : true } ) ;
111+
112+ // The content gets passed down into the step header components so we need to
113+ // notify the stepper if they come in later or they might not get picked up.
114+ if ( step ) {
115+ step . stepLabel = this ;
116+ stepper ?. _stateChanged ( ) ;
117+ }
118+ }
119+ }
120+
103121@Component ( {
104122 selector : 'cdk-step' ,
105123 exportAs : 'cdkStep' ,
@@ -113,7 +131,16 @@ export class CdkStep implements OnChanges {
113131 _displayDefaultIndicatorType : boolean ;
114132
115133 /** Template for step label if it exists. */
116- @ContentChild ( CdkStepLabel ) stepLabel : CdkStepLabel ;
134+ @ContentChild ( CdkStepLabel )
135+ get stepLabel ( ) {
136+ return this . _stepLabel ;
137+ }
138+ set stepLabel ( label : CdkStepLabel ) {
139+ this . _stepLabel = label ;
140+ }
141+ protected _stepLabel : CdkStepLabel ;
142+
143+ // stepLabel: CdkStepLabel
117144
118145 /** Forms that have been projected into the step. */
119146 @ContentChildren (
@@ -122,9 +149,7 @@ export class CdkStep implements OnChanges {
122149 // the directives. The type is marked as `Partial` in case we run into a class that provides
123150 // itself as `ControlContainer` but doesn't have the same interface as the directives.
124151 ControlContainer ,
125- {
126- descendants : true ,
127- } ,
152+ { descendants : true } ,
128153 )
129154 protected _childForms : QueryList < Partial < NgForm | FormGroupDirective > > | undefined ;
130155
0 commit comments