-
Notifications
You must be signed in to change notification settings - Fork 24.8k
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
DI: provide an equivalent to @SkipSelf in Injector.get() #17898
Comments
Closing in on a year now. Any update on this. it seems like a simple fix, as the functionality already exists. |
It appears that this functionality was added as part of #22005 in this commit So if you want to use the equivalent of @SkipSelf you would write: But when I call this from within a Directive and use SkipSelf it is still returning the current instance of the directive. |
Could it be related to #34066? |
This functionality was added to the Injector API but was not implemented in the NodeInjector class which seems like an oversight. I have been looking for an alternative but haven't found a way to use the SkipSelf flag from an autowired injector yet. |
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. |
Thank you for submitting your feature request! Looks like during the polling process it didn't collect a sufficient number of votes to move to the next stage. We want to keep Angular rich and ergonomic and at the same time be mindful about its scope and learning journey. If you think your request could live outside Angular's scope, we'd encourage you to collaborate with the community on publishing it as an open source package. You can find more details about the feature request process in our documentation. |
Closing as covered by #31776. |
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. |
I'm submitting a ...
Current behavior
It is currently possible, when injecting a dependency in a constructor, to use
@Optional()
to avoid an error when the dependency is not found, and@SkipSelf()
to search directly on the parent injector. For instance, a typical use case for@SkipSelf()
is self-nested components that need to inject their parent.When working with more "dynamic" dependency injection, however, you need to rely on an Injector object. It offers an equivalent to
@Optional()
by accepting anotFoundValue
, but there is no way to emulate@SkipSelf()
. The parent injector is not public, and the only method is.get()
which will obviously look in this injector first.Expected behavior
The
get()
method should accept a third optional argument allowing us to search directly on the parent injector:It would default to
false
, evidently.What is the motivation / use case for changing the behavior?
It should be logical for
Injector
to offer the exact same capabilities as constructor-level dependency injection.Please tell us about your environment
The text was updated successfully, but these errors were encountered: