So, I've 3 modules in my Angular app.
// main module
@NgModule({
declarations: [AppComponent],
bootstrap: [AppComponent]
})
export class AppModule { }
// lazy loading module
@NgModule({
})
export class ClinicModule { }
// lazy loading module
@NgModule({
})
export class PatientModule { }
we know, for lazyloading behavior purposes, I cant import ClinicModule and PatientModule in my AppModule.
But, there is a service inside of ClinicModule called PatientGroupService.
I use this service in ClinicModule for CRUD operations and in PatientModule to bring the PatientGroup List.
So, I need it in both module, the only way, I found, to get only one instance of PatientGroupService without import ClinicModule in AppModule was provide PatientGroupService directly on AppModule, like this
// main module
@NgModule({
declarations: [AppComponent],
bootstrap: [AppComponent],
providers :[PatientGroupService]
})
export class AppModule { }
You may noticed, it is not a "global service", only a service used for 2 non main modules.
It works, but I wanna know:
- Is this the "correct way" to achieve my goal?
- Is there another/better way to do that?