Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
import { Observable, Subject } from 'rxjs';
export class MessageService {
private static _instance: MessageService;
private messages: string[] = [];
private subject: Subject<string[]> = new Subject();
add(message: string) {
clear() {
this.messages = [];;
getMessages(): Observable<string[]> {
return this.subject.asObservable();
public static get Instance(): MessageService {
// Do you need arguments? Make it a regular method instead.
return this._instance || (this._instance = new this());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment