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

Injecting deps via token from same file into a scoped Injectable fails #22559

Closed
jelbourn opened this issue Mar 2, 2018 · 2 comments
Closed
Labels
area: core Issues related to the framework runtime core: di freq3: high hotlist: components team Related to Angular CDK or Angular Material P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent type: bug/fix
Milestone

Comments

@jelbourn
Copy link
Member

jelbourn commented Mar 2, 2018

Overview

  1. You have an InjectionToken defined in some file
  2. You have an @Injectable in that same file that injects a dep via that token

Easiest workaround is to move the token to another file.

Reproduction

  1. Clone https://github.com/jelbourn/material2/commits/cdk-tree-shakable-services
  2. npm i
  3. gulp test

Generated code (snippet)

exports.LIVE_ANNOUNCER_ELEMENT_TOKEN = new core_1.InjectionToken('liveAnnouncerElement', {
    scope: core_1.APP_ROOT_SCOPE,
    factory: function () { return null; },
});

...

LiveAnnouncer.ngInjectableDef = i0.defineInjectable({ factory: function LiveAnnouncer_Factory() { return new LiveAnnouncer(i0.inject(LIVE_ANNOUNCER_ELEMENT_TOKEN, null, 0), i0.inject(i1.DOCUMENT)); }, token: LiveAnnouncer, scope: i0.APP_ROOT_SCOPE });

Error

Because LIVE_ANNOUNCER_ELEMENT_TOKEN isn't referenced off of exports, the second part of the code is just trying to reference a nonexistent identifier.

a11y/live-announcer/live-announcer.spec.ts(4,24): error TS2305: Module '"/Users/jelbourn/material2/src/cdk/a11y/live-announcer/live-announcer"' has no exported member 'LIVE_ANNOUNCER_ELEMENT_TOKEN'.
@jelbourn jelbourn added hotlist: components team Related to Angular CDK or Angular Material hotlist: angular-core-team area: core Issues related to the framework runtime labels Mar 2, 2018
@ngbot ngbot bot added this to the needsTriage milestone Mar 2, 2018
@ngbot ngbot bot modified the milestones: needsTriage, Backlog Apr 10, 2018
@jelbourn jelbourn added P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent and removed P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent labels Oct 1, 2020
@ngbot ngbot bot modified the milestones: Backlog, needsTriage Oct 1, 2020
@jelbourn jelbourn added the P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent label Oct 1, 2020
@ngbot ngbot bot modified the milestones: needsTriage, Backlog Oct 1, 2020
@jelbourn
Copy link
Member Author

jelbourn commented Apr 1, 2022

This is probably obsolete

@jelbourn jelbourn closed this as completed Apr 1, 2022
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators May 2, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: core Issues related to the framework runtime core: di freq3: high hotlist: components team Related to Angular CDK or Angular Material P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent type: bug/fix
Projects
None yet
Development

No branches or pull requests

3 participants