Can lazy-loaded modules share the same instance of a service provided by their parent?

后端 未结 3 781
被撕碎了的回忆
被撕碎了的回忆 2020-11-28 07:48

I\'ve just run into a problem with a lazy-loaded module where parent and child module both require the same service but create an instance each. The declaration is identical

3条回答
  •  悲哀的现实
    2020-11-28 08:41

    I have a separate layout module with a service, this service needed to work on other feature modules, using lazy load

    I was able to solve the problem by exporting the service, straight from the layout module

    @NgModule({
        declarations: [...],
        imports: [...],
        exports: [...],
    })
    export class LayoutModule {
        ...
    }
    
    export { LayoutService }
    

提交回复
热议问题