Skip to content

Instantly share code, notes, and snippets.

@Dornhoth
Created September 11, 2020 19:19
Show Gist options
  • Save Dornhoth/cf0d58f30d0712e556ac2685c282e8d8 to your computer and use it in GitHub Desktop.
Save Dornhoth/cf0d58f30d0712e556ac2685c282e8d8 to your computer and use it in GitHub Desktop.
import { Component, OnInit } from '@angular/core';
import { SingletonService } from './singleton.service';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})
export class AppComponent implements OnInit {
constructor(
private singletonService: SingletonService
) { }
ngOnInit(): void {
this.singletonService.someMethod();
}
}
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';
import { ModuleAModule } from './moduleA/moduleA.module';
import { SingletonService } from './singleton.service';
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
ModuleAModule,
],
providers: [SingletonService],
bootstrap: [AppComponent]
})
export class AppModule { }
import { Component, OnInit } from '@angular/core';
import { SingletonService } from '../singleton.service';
@Component({
selector: 'app-module-a',
templateUrl: './moduleA.component.html',
styleUrls: ['./moduleA.component.scss']
})
export class ModuleAComponent implements OnInit {
constructor(
private singletonService: SingletonService
) { }
ngOnInit(): void {
this.singletonService.someMethod();
}
}
import { NgModule } from '@angular/core';
import { SingletonService } from '../singleton.service';
import { ModuleAComponent } from './moduleA.component';
@NgModule({
declarations: [
ModuleAComponent
],
exports: [ModuleAComponent],
providers: [SingletonService],
})
export class ModuleAModule { }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment