Skip to content

Instantly share code, notes, and snippets.

@Devcon4
Last active September 2, 2018 22:16
Show Gist options
  • Select an option

  • Save Devcon4/00a857372bb0742904d4a3ff5d1cafee to your computer and use it in GitHub Desktop.

Select an option

Save Devcon4/00a857372bb0742904d4a3ff5d1cafee to your computer and use it in GitHub Desktop.
CreateObservable.ts
import { of, BehaviorSubject } from 'rxjs';
import { take, map } from 'rxjs/operators';
// Create observable.
const obs = of([1, 2, 3]);
const sub1 = obs.subscribe(console.log);
const sub2 = obs.pipe(take(1)).subscribe(console.log);
const sub3 = obs.pipe(map(arr => arr[0])).subscribe(console.log);
// output.
// [ 1, 2, 3 ]
// [ 1, 2, 3 ]
// 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment