Skip to content

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

Closed

Description

@sis0k0

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions