Skip to content

Instantly share code, notes, and snippets.

@Dornhoth
Created September 11, 2020 20:20
Show Gist options
  • Save Dornhoth/f11bfff342f6574b6db355d533bdcabd to your computer and use it in GitHub Desktop.
Save Dornhoth/f11bfff342f6574b6db355d533bdcabd to your computer and use it in GitHub Desktop.
import { ModuleWithProviders, NgModule } from '@angular/core';
import { SingletonService } from './singleton.service';
import { ModuleAComponent } from './moduleA.component';
@NgModule({
declarations: [
ModuleAComponent
],
exports: [ModuleAComponent],
})
export class ModuleAModule {
static forRoot(): ModuleWithProviders<ModuleAModule> {
return { ngModule: ModuleAModule, providers: [SingletonService] };
}
static forChild(): ModuleWithProviders<ModuleAModule> {
return {
ngModule: ModuleAModule, providers: [{ provide: SingletonService, useValue: {} }]
};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment