Getting the context of the template inside of which my component has been rendered
See original GitHub issue🚀 feature request
Relevant Package
Description
So i posted a question about this on StackOverflow some time ago and since until now i had 0 question/comments and had to came up with a pretty ugly hack i think it’s time to bring this to your attention.
Without repeating everything i’ve already said in that question, my request is if we can please have a non hacky way to retrieve the context of the template inside of which a component has been rendered
Describe the solution you’d like
The ViewEngine solution to this problem actually sounds nice:
(<any>this._viewContainer)._view.context
Can we please have this on Ivy also?
Describe alternatives you’ve considered
Ugly Alternative 1: (<any>this._viewContainer)._hostView.debug.context
Ugly Alternative 2: (<any>this._viewContainer)._hostView.find(t => t && !!t.$implicit)
Issue Analytics
- State:
- Created 4 years ago
- Reactions:10
- Comments:13 (6 by maintainers)
Top Results From Across the Web
Getting the context of the template inside of which my ...
From inside <single-item> i want to be able to access the item instance, without having to pass it to each <single-item> component, aka,...
Read more >Everything you need to know about ng-template, ng-content ...
This is what we call Content Projection. The content will be rendered inside the <ng-content> within the component.
Read more >Templates in the Microsoft Graph Toolkit
Use custom templates to modify the content of a component. ... Looping; Template context; Template rendered event; Styling.
Read more >Context - React
Context. Context provides a way to pass data through the component tree without having to pass props down manually at every level.
Read more >Rendering A TemplateRef As A Child Of The Body Element In ...
I created <app-body-content> . This Angular component takes the "child content" from the calling context and projects it / renders it in the ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@EmaGht we’ve reviewed this issue during the team’s triage meeting and decided that this is not something we want to implement. There are 3 explicit ways of passing info to a component:
We don’t want to add another way that would be implicit.
AFAIK you cannot use a custom injector when creating a view from a template.