I have an interesting question. I have 2 modules. app.module.ts (AppModule) and listings.module.ts (ListingsModule). ListingsModule has a service, let us call it service A. A needs to be a singleton global service, meaning that all of the other components and services need to be able to interact with the same A.
For this I firstly tried declaring A as a provider in ListingsModule, but this did not work as expected as it was only being declared a singleton for use for components and services under ListingsModule, but I also needed to use it under other modules and under AppModule. I thus concluded that I need to export this service from ListingsModule and import and provide this under AppModule, but this did not work as expected.
A is ListingsStoreService.
//Stores
import { ListingsStoreService } from './shared/listings-store.service';
//Modules
import { SharedModule } from './../shared/shared.module';
import { HeaderModule } from './../header/header.module';
@NgModule({
imports: [
SharedModule,
HeaderModule,
ListingsRoutingModule
],
declarations: [
ListingsComponent
],
exports: [
ListingsStoreService
],
providers: [ ]
})
export class ListingsModule {
}
The following code asks me to declare or import ListingsStoreService, for it to be exportable. If I declare ListingsStoreService then it gives me another error. I can apparently only provide this service.
What is the right approach here? How do I make this work?