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.

DI - Handle the "InjectFlags" in Injector_.get()

See original GitHub issue

πŸš€ feature request

Relevant Package

This feature request is for @angular/core

Description

At the moment the Injector_.get() implementation doesn’t handle the InjectFlags. I’d like the feature so that I can use the component Injector like this:

@Component(...)
export class SomeComponent {
    // Here I get an instance of Injector_
    constructor(injector: Injector) {
        this.myService = injector.get(SomeService, null, InjectFlags.SkipSelf);
    }
}

Describe the solution you’d like

It looks like you already handle the DeepFlags. refs.ts:342
You probably just need to map and pass the InjectFlags to the resolveDeep() function

class Injector_ implements Injector {
  ...
  get(token: any, notFoundValue: any = Injector.THROW_IF_NOT_FOUND): any {
    ...
    return Services.resolveDep(
        this.view, this.elDef, allowPrivateServices,
        {flags: DepFlags.None, token, tokenKey: tokenKey(token)}, notFoundValue);
  }
}

I don’t think I have enough knowledge of the project to submit a PR by myself, so I’m relying on you for this.
Thanks in advance for your work

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:16
  • Comments:13 (3 by maintainers)

github_iconTop GitHub Comments

5reactions
kpeterbauercommented, Jul 10, 2020

I would call it a bug, not a feature: The provided Injector clearly does not behave as defined by the API documentation:

https://angular.io/api/core/Injector

3reactions
stupidawesomecommented, Feb 25, 2020

NodeInjector isn’t passing the flag here di.ts#L628

export class NodeInjector implements Injector {
  constructor(
      private _tNode: TElementNode|TContainerNode|TElementContainerNode|null,
      private _lView: LView) {}

  get(token: any, notFoundValue?: any): any {
    return getOrCreateInjectable(this._tNode, this._lView, token, undefined, notFoundValue);
  }
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Injector - Angular
get() link Β· mode_edit code. Retrieves an instance from the injector based on the provided token. 4 overloadsΒ ...
Read more >
Angular Injector, have multiple InjectFlags in get method
How can we have multiple InjectFlags? Something for eg. that would resemble @Optional() @SkipSelf() private _type1: Type1;.
Read more >
A Deep Dive into @Injectable and providedIn in Ivy - Angular ...
In this article I want to explain how Angular @Injectable decorator works under the hood and how providedIn property is processed by AngularΒ ......
Read more >
Using root-provided Injectables in non-DI places | tnc
Imagine you have a LogService that will handle API errors and log the ... It is going to get very verbose to apply...
Read more >
Injector - Angular ζ—₯本θͺžγƒ‰γ‚­γƒ₯パンテーション
Injectors are configured with providers that associate dependencies of various types with injection tokens. ... "DI Providers". ... get()link.
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