Skip to content

Instantly share code, notes, and snippets.

@Dornhoth
Created September 11, 2020 19:15
Show Gist options
  • Save Dornhoth/6896c0602ca6f3dfa485d2395bb841bb to your computer and use it in GitHub Desktop.
Save Dornhoth/6896c0602ca6f3dfa485d2395bb841bb to your computer and use it in GitHub Desktop.
Singleton
import { Injectable } from '@angular/core';
@Injectable()
export class SingletonService {
static instances = 0;
constructor() {
SingletonService.instances += 1;
}
someMethod(): void {
console.log(`There are ${SingletonService.instances} instances of the service`);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment