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

Tree-shakable providers scoped to the root injector don't get registered #1417

Closed
sis0k0 opened this issue Jul 6, 2018 · 0 comments · Fixed by #1418
Closed

Tree-shakable providers scoped to the root injector don't get registered #1417

sis0k0 opened this issue Jul 6, 2018 · 0 comments · Fixed by #1418
Assignees
Milestone

Comments

@sis0k0
Copy link
Contributor

sis0k0 commented Jul 6, 2018

What are tree-shakable providers?

Angular 6 introduced a new way to register providers in order to make them tree-shakable. That gives Angular the ability to remove services that are not used in the application from the final output.
To create a tree-shakable provider you need to specify the injector which injects a service in the metadata of that service. For example:

@Injectable({
  providedIn: 'root',
})
export class Service {
}

Setting the value to root ensures that the service is scoped to the root injector.

Issue

The tree-shakable providers scoped to the root injector (the above example) don't get registered in NativeScript, which results in the following error:

Error: NullInjectorError: No provider for Service!

Solution

The NativeScriptModule should be marked as root. We can do that by providing the APP_ROOT token in the metadata of that module.

Demo

https://play.nativescript.org/?template=play-ng&id=tCY7bL

@sis0k0 sis0k0 added the bug label Jul 6, 2018
@sis0k0 sis0k0 added this to the 6.1 (TBD) milestone Jul 6, 2018
@sis0k0 sis0k0 self-assigned this Jul 6, 2018
sis0k0 added a commit that referenced this issue Jul 6, 2018
@ghost ghost added the in progress label Jul 6, 2018
@ghost ghost removed bug in progress labels Jul 16, 2018
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

Successfully merging a pull request may close this issue.

1 participant