Skip to content

Instantly share code, notes, and snippets.

@anmolio
Last active May 10, 2020 10:57
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 anmolio/1a31abfe5db5ce36fd5b2e696466a04a to your computer and use it in GitHub Desktop.
Save anmolio/1a31abfe5db5ce36fd5b2e696466a04a to your computer and use it in GitHub Desktop.
Example of an angular service using RxJs BehaviorSubject for data sharing.
import { Injectable } from '@angular/core';
import { BehaviorSubject } from 'rxjs';
@Injectable()
export class StatusService {
private statusSource = new BehaviorSubject('OFF'); // set default status
currentStatus = this.statusSource.asObservable();
constructor() { }
changeStatus(status: string) {
this.statusSource.next(status)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment