Search code examples
angularangular-servicesangular-module

Angular: can components of an imported module access the services provided in the parent module?


If I have module-A with component-A and module-B with service-B and I import module-A into Module-B, will component-A be able to access service-B?


Solution

  • No, when importing module A into B, Module A is accessible by module B but not vice versa.

    Although services are accessible to all components declared by a module, it doesn't apply on imported module's components due to the simple fact that regardless of the location where they are used, they are still living in Module A's context where they have no access to Module B's services.