简体   繁体   中英

Angular 5 and services in lazy loading

I would like to ask a question regarding angular 5 application structure and maybe it is even related to the architecture of it. I have an application that is using lazy loading. I got to a point in which I need to make the same api call from 2 different lazy loaded modules. I would like to know how to approach this problem if anybody can help me with it

When you provide a service in Angular it is available everywhere. Only services provided in a lazy loaded module are not available throughout the app, because they will be instanciated when your module loads, not before.

When you need a service in the whole app, then you must provide it in a eagerly loaded module. Common pattern would be a core module, which holds all services and is loaded by the app.module.

Services provided in eagerly loaded modules can be injected everywhere even in lazy loaded modules.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM