Search code examples
angulartypescriptangular2-servicesangular2-injection

Where a should inject service, which should be visible in all app? (angular2)


I want to create NewService. And I want to have possibility to call it from all application?

Where I should inject it in SharedModule (module which exports all reusable modules) or in AppModule ( main module of my application)

@NgModule({

  providers: [
     // Here?
  ]
})

Solution

  • It doesn't matter if you add it to the AppModule directly or to a feature module as long as the module is not lazy loaded.

    Lazy loaded modules have their own root scope and providers added there are only visible to the lazy loaded module.