| // Import all | |
| import Rx from "rxjs/Rx"; | |
| Rx.Observable | |
| .interval(200) | |
| .take(9) | |
| .map(x => x + "!!!") | |
| .bufferCount(2) | |
| .subscribe(::console.log); | |
| // Add operators (my favourite) | |
| import {Observable} from "rxjs/Observable"; | |
| import "rxjs/add/observable/interval"; | |
| import "rxjs/add/operator/take"; | |
| import "rxjs/add/operator/map"; | |
| import "rxjs/add/operator/bufferCount" | |
| Observable | |
| .interval(200) | |
| .take(9) | |
| .map(x => x + "!!!") | |
| .bufferCount(2) | |
| .subscribe(::console.log); | |
| // JavaScript ES7 Function Bind Syntax | |
| import {Observable} from "rxjs/Observable"; | |
| import "rxjs/add/observable/interval"; | |
| import {take} from "rxjs/operator/take"; | |
| import {map} from "rxjs/operator/map"; | |
| import {bufferCount} from "rxjs/operator/bufferCount" | |
| Observable | |
| .interval(200) | |
| ::take(9) | |
| ::map(x => x + "!!!") | |
| ::bufferCount(2) | |
| .subscribe(::console.log); |
This comment has been minimized.
This comment has been minimized.
gruppjo
commented
Jan 24, 2017
|
@zemd, yes it does. Thank you! |
This comment has been minimized.
This comment has been minimized.
kamok
commented
Apr 25, 2017
|
Why do I have access to interval and take by simply importing |
This comment has been minimized.
This comment has been minimized.
|
@kamok you could |
This comment has been minimized.
This comment has been minimized.
piecioshka
commented
Sep 5, 2017
|
In my case (Angular 4 application generated by @angular/cli) I used that syntax: import * as Rx from "rxjs/Rx";Because I get error:
|
This comment has been minimized.
This comment has been minimized.
briancodes
commented
Dec 15, 2017
|
Dont use rxjs-operators.ts
app.module.ts
You won't need to import anywhere else in your application now |
This comment has been minimized.
This comment has been minimized.
mikerames
commented
Jan 28, 2018
|
@briancodes Thanks, you have the best solution. |
This comment has been minimized.
This comment has been minimized.
jpduckwo
commented
Feb 27, 2018
|
We should all be moving to this https://github.com/ReactiveX/rxjs/blob/master/doc/pipeable-operators.md for all the reasons listed in the article under 'Why?' |
This comment has been minimized.
This comment has been minimized.
shikhaBasra
commented
Apr 18, 2018
•
|
@briancodes import './rxjs-operators'; Following your suggestion, If now I am using 'map' operator in some component.ts file, it asks for importing library for map operator. Other point is that, If I am using on map and do operator in my application using import 'rxjs/add/operator/map', |
This comment has been minimized.
This comment has been minimized.
sorcamarian
commented
Jul 3, 2018
|
Thank you for your help! |
This comment has been minimized.
zemd commentedJan 9, 2017
Also important to notice that to import
raceoperator which will be used out of observable's scope, you should useraceStatic.For example,
Spent extra hour to find out how to use it (( hope this help someone.