I an not sure how does @ContentChild
accept an InjectionToken
in Angular v14
. I could not find suitable update document.
I have a WIDGET_TOKEN
export const WIDGET_TOKEN = new InjectionToken("WIDGET_TOKEN")
VelocityWidgetComponent
is provided for injection token WIDGET_TOKEN
@Component({
providers:[
{provide:WIDGET_TOKEN,useExisting:VelocityWidgetComponent}
]
})
export class VelocityWidgetComponent implements OnInit {}
WidgetWrapperComponent
token wraps VelocityWidgetComponent
and tries to access it through @ContentChild
@Component({
styleUrls: ['./widget-wrapper.component.css']
})
export class WidgetWrapperComponent implements OnInit {
@ContentChild(WIDGET_TOKEN,{static:true}) widget:any;
}
–* app.component.html *–
<app-widget-wrapper>
<app-velocity-widget></app-velocity-widget>
</app-widget-wrapper>
In Angular v12 example it throws an error. I understand this error, as per docs @ContentChild
does not accept a non-string token as selector.
But how Angular v14 example accept a non-string token as selector? and how does the dependency resolved when WIDGET_TOKEN
is provided in the VelocityWidgetComponent
which is child of the WidgetWrapperComponent
(requested component).