-
-
Notifications
You must be signed in to change notification settings - Fork 240
Closed
Milestone
Description
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.