-
Notifications
You must be signed in to change notification settings - Fork 25.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ability to request injection from a specific parent injector #40974
Comments
|
@waterplea - it would be really helpful in setting a priority for this feature, if you were to give some concrete examples of scenarios where this would be useful. |
|
Well, the example with |
|
This is how I would have constructed this example. Is that one of the options you considered? |
|
Now I solve these things with tokens, it's cleaner than injecting stuff in parent container that it doesn't need: But I'm not looking for workarounds, I'm just saying if we can query stuff inwards with children, it would help to be able to do it upward. |
|
Right, thanks for providing the component provider approach. This is all helpful in working out the priority for this. For what it's worth I would not expect a second decorator, but instead a parameter on |
|
Another viable usecase! <parent>
<child></child>
</parent>Both |
|
Just a heads up that we kicked off a community voting process for your feature request. There are 20 days until the voting process ends. Find more details about Angular's feature request process in our documentation. |
|
Edited title and body of the request to the options object for |
|
While this is an interesting idea, I don't think it's a feature we would want to add to the DI system. A strong argument against is that it breaks the natural encapsulation provided by DI, where a parent can choose to override providers being passed to the children. Being able to reach into the parent injector and inject tokens directly breaks that encapsulation. |
|
In case someone's interested, I was playing with new |
|
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Title edited from: Add options to @Inject decorator to read particular provider
🚀 feature request
Relevant Package
This feature request is for @angular/core
Description
When we use
@ViewChild/renor@ContentChild/renwe can query using DI token and then provide additionalreadoption to tell what other token do we want to actually read from it:It would be super awesome if we could do it with constructor params!
Describe the solution you'd like
Add options to
@Injectdecorator:Describe alternatives you've considered
Create tokens and add
useExistingproviders to directives, but it's not always known beforehand what tokens I might need to inject later on.Use cases:
ElementRefof a particular parent elementChangeDetectorRefof a wrapping element so content children can trigger change detection of theirOnPushparentThe text was updated successfully, but these errors were encountered: