I'm submitting a ...
[ ] Regression (behavior that used to work and stopped working in a new release)
[ ] Bug report
[x] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question
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.
export class MyComponent {
constructor(@Optional() @SkipSelf() parent: MyComponent) {}
}
When working with more "dynamic" dependency injection, however, you need to rely on an Injector object. It offers an equivalent to @Optional() by accepting a notFoundValue, 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:
abstract get<T>(token: Type<T>|InjectionToken<T>, notFoundValue?: T, skipSelf?: boolean): T;
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
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
Injectorto offer the exact same capabilities as constructor-level dependency injection.Please tell us about your environment