Skip to content
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

[ngtsc] Link dependencies injected with @Inject decorator with the provider #28

Open
GrandSchtroumpf opened this issue Sep 1, 2020 · 0 comments

Comments

@GrandSchtroumpf
Copy link
Contributor

The problem

With this example :

const TOKEN = new InjectionToken();
@Component({
  ...
  providers: [{ provide: TOKEN, useValue: true }]
})
export class MainComponent {
  constructor(@Inject(TOKEN) isTrue) {}
}

@NgModule({
  declarations: [MainComponent],
  providers: [{ provide: TOKEN, useValue: false }]
})

When running :

const [component] = workspace.getAllComponents();
const [token] = component.getDependencies();

The value token should reference the provider inside the component (with the value true).
Current behavior: returns undefined.


How to solve :

  1. Do more research on the compiler to found out if this information is hold somewhere
  2. If not create a ProviderRegistry that keeps track of all the provider per class declaration or at the root if providedIn: 'root'
  3. For components & directives we can use the scope to look for the closest implementation of the provider.
  4. For injectables & Pipes there is no scope available, we should scan every modules & root field of the ProviderRegistry.

Hopefully there is a built-in solution in the angular compiler so we can stop at step 1 🤞

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant