Angular: Get reference to parent component when being content-projected
I can only see two ways (except DOM hacking):
- Switch to using templates. Ticket is still open: 14935. Currently it is impossible to override injector in
viewContainerRef.createEmbeddedView
, however there is option to pass context information (example context-parameter-in-angular, or useNgTemplateOutlet
). - Use DI to be able to find projected child components and call their methods. Each child component provides itself using common token
{provide: Token, useExisting: forwardRef(() => Child)}
, it allows to use@ContentChildren(Token)
and get list of all projected children, and call any method/setter.