Last active
May 10, 2020 10:57
-
-
Save anmolio/1a31abfe5db5ce36fd5b2e696466a04a to your computer and use it in GitHub Desktop.
Example of an angular service using RxJs BehaviorSubject for data sharing.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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