You could wrap jQuery's ajax request with your own function that returns RxJs's observable:
import { Observable } from 'rxjs/Observable';
import { Subject } from 'rxjs/Subject';
const jQuery = require('jquery');
/**
* Function to call in place of jQuery.ajax(...).
*/
export const ajax = function(options: any) : Observable<any> {
// Init a new observable subject.
const subject = new Subject<any>();
// Make the ajax call.
jQuery.ajax(Object.assign({}, options, { complete, error, success }));
// Return the subject as an observable.
return subject.asObservable();
/**
* Fires when jQuery's request calls its `complete` callback.
*/
function complete(xhr: any, textStatus: string) : void {
subject.complete({ xhr, textStatus });
}
/**
* Fires when jQuery's request calls its `error` callback.
*/
function error(xhr: any, textStatus: string, errorThrown: string) : void {
subject.error({ xhr, textStatus, errorThrown });
}
/**
* Fires when jQuery's request calls its `success` callback.
*/
function success(data: any, textStatus: string, xhr: any) : void {
subject.next({ data, textStatus, xhr });
}
}