Understanding Angular's Dependency Injector when lazy loading modules

Instead of restating the details, we will paraphrase directly from Angular's official documentation (https://angular.io/guide/ngmodule-faq#!#q-why-child-injector), which explains this perfectly:

Angular adds @NgModule.providers to the application root injector unless the module is lazy loaded. For a lazy-loaded module, Angular creates a child injector and adds the module's providers to the child injector. This means that a module behaves differently depending on whether it's loaded during application start or lazily loaded later. Neglecting that difference can lead to adverse consequences. Why doesn't Angular add lazy-loaded providers to the app root injector as it does ...

Get NativeScript for Angular Mobile Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.