question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Getting the context of the template inside of which my component has been rendered

See original GitHub issue

🚀 feature request

Relevant Package

@angular/core

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:closed
  • Created 4 years ago
  • Reactions:10
  • Comments:13 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
pkozlowski-opensourcecommented, Apr 20, 2022

@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:

  • inputs
  • content
  • DI

We don’t want to add another way that would be implicit.

1reaction
pauldrapercommented, Nov 7, 2020

simply create a custom injector when you instantiate the template

AFAIK you cannot use a custom injector when creating a view from a template.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found