Skip to content

Instantly share code, notes, and snippets.

@webhacking
Created January 24, 2019 04:17
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 webhacking/31b5de8eed6e4ae8ced110846573b203 to your computer and use it in GitHub Desktop.
Save webhacking/31b5de8eed6e4ae8ced110846573b203 to your computer and use it in GitHub Desktop.
BehaviorSubject Example
/* Initialize with initial value of 42 */
import {BehaviorSubject} from 'rxjs/internal/BehaviorSubject';
const subject = new BehaviorSubject(42);
const subscription = subject.subscribe((x: number) => {
console.log(`Next: ${String(x)}`);
}, (error: Error) => {
console.log(`Error: ${error}`);
}, () => {
console.log('Completed');
});
// => Next: 42
subject.next(56);
// => Next: 56
subject.complete();
// => Completed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment