Reactive-Extensions / RxJS-DOM

HTML DOM Bindings for the Reactive Extensions for JavaScript
http://reactivex.io
Other
437 stars 99 forks source link

Call function on Ajax #126

Closed yann-stepienik-cko closed 7 years ago

yann-stepienik-cko commented 7 years ago

I can't call anything else than subscribe on the ajax observable

import { ajax } from 'rxjs/observable/dom/ajax';

return ajax({
  url : url
}).map((res) => {  //  doesn't exists
   return res;
})
paulpdaniels commented 7 years ago

Two things:

1) Wrong library you want here 2) Unless you take the kitchensink approach and import rxjs/Rx (I think) then you need to add each operator that you want to use.

import 'rxjs/operator/add/map';
import 'rxjs/operator/add/filter';
/// etc etc
yann-stepienik-cko commented 7 years ago

Hello!

1- not sure what you mean ? Ajax is part of RXJS-DOM isn't it 2- Tried it :

import { Observable } from 'rxjs/Observable';
import { map } from 'rxjs/operator/map';
import { ajax } from 'rxjs/observable/dom/ajax';

ajax({...}).map(...)

I get :

TypeError: (0 , _ajax.ajax)(...).map is not a function

But thanks you for your comment as you mentioned, if I import the full set of rxjs/Rx it does work indeed. I'll do that for now, that will do, thanks again !

Working code :

import { Observable } from 'rxjs/Rx';
import { ajax } from 'rxjs/observable/dom/ajax';

ajax({...}).map(...)
paulpdaniels commented 7 years ago

@yann-stepienik-cko technically yes there is Ajax in this library but this is for RxJS 4 and below. RxJS 5 keeps ajax in the main library https://github.com/ReactiveX/rxjs/tree/master/src/observable/dom since they don't yet have a module strategy.

Let me know if you have any other questions. And if you have further questions I would lodge issues on that board or stackoverflow.

yann-stepienik-cko commented 7 years ago

Oh I see thanks for clarification, I'm closing the issue !