Skip to content

Instantly share code, notes, and snippets.

@benhickson
Created July 10, 2020 02:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benhickson/203493c96ff58c7473aaf02571dc072c to your computer and use it in GitHub Desktop.
Save benhickson/203493c96ff58c7473aaf02571dc072c to your computer and use it in GitHub Desktop.
import { Injectable } from '@angular/core';
import { BehaviorSubject } from 'rxjs';
@Injectable({
providedIn: 'root'
})
export class PlayerService {
private currentPlayerSource = new BehaviorSubject(0); // 0 is the default value
currentPlayer = this.currentPlayerSource.asObservable();
constructor() { }
changeCurrentPlayer(player: number): void {
this.currentPlayerSource.next(player);
console.log('current player id:', player);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment