Skip to content

Instantly share code, notes, and snippets.

@LayZeeDK
Created December 11, 2018 00:01
Show Gist options
  • Save LayZeeDK/e4dd2fb1331bb01a01c9d75ad2413b79 to your computer and use it in GitHub Desktop.
Save LayZeeDK/e4dd2fb1331bb01a01c9d75ad2413b79 to your computer and use it in GitHub Desktop.
The forRoot pattern for singleton services
import { ModuleWithProviders, NgModule } from '@angular/core';
import { MyComponent } from './my.component';
import { PreSixSingletonService } from './pre-six-singleton.service';
@NgModule({
declarations: [
MyComponent,
],
})
export class PreSixModule {
static forRoot(): ModuleWithProviders {
return {
ngModule: PreSixmodule,
providers: [
PreSixSingletonService,
],
};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment