rxjs

Property 'json' does not exist on type '{}'

China☆狼群 提交于 2019-12-29 05:45:06
问题 I have an abstract base class in Typescript that looks like this: import {Http, Headers, Response} from 'angular2/http'; export abstract class SomeService { constructor(private http:Http) {} protected post(path:string, data:Object) { let stringifiedData = JSON.stringify(data); let headers = new Headers(); headers.append('Content-Type', 'application/json'); headers.append('Accept', 'application/json'); this.http.post(`http://api.example.com/${path}`, stringifiedData, { headers }) .map(res =>

Angular2. How can I check if an observable is completed?

旧时模样 提交于 2019-12-29 05:06:05
问题 In my page there is a button that generates a report. That report needs data that is loaded using a http call to a rest endpoint when the page is loaded, but I do not have a guarantee that they are loaded when the user presses the report button. How can I watch the observable to see if it is completed, and if incomplete, to wait on the action until the http call is completed? Here is some of the code: loadCompanies(): void { this._companyService.getCompanies().subscribe( response => { this

RxJS Continue Listening After Ajax Error

南楼画角 提交于 2019-12-29 03:37:49
问题 RxJs stops listening to click events when an inner observable errors (Ajax request). I'm trying to figure out how to keep the event listener hooked to the button click event and gracefully handle the inner ajax error. Here is my example code and a link to plunkr var input = $("#testBtn"); var test = Rx.Observable.fromEvent(input,'click'); var testAjax = function() { return Rx.Observable.range(0,3).then(function(x){ if(x==2)throw "RAWR"; //Simulating a promise error. return x; }); } test.map

How to build an rx poller that waits some interval AFTER the previous ajax promise resolves?

不羁岁月 提交于 2019-12-29 01:47:28
问题 Been working on a few approaches to this. Basically, I don't want a poller that kicks off an ajax every 30 seconds from the start of polling -- I want a poller that kicks off requests 30 seconds AFTER the previous request returns. Plus, I want to work in some strategy around exponential back-off for failures. Here's what I have so far (Rx4): rx.Observable.create(function(observer) { var nextPoll = function(obs) { // the action function invoked below is what i'm passing in // to my poller

RxJs Array of Observable to Array

痴心易碎 提交于 2019-12-28 16:30:24
问题 For a Web-Application written with Angular2 in TypeScript, I need to work with RxJs Observable s. As I never used rxjs before and I am new to reactiveprogramming in general, I sometimes have some difficulties finding the right way to do some specific things. I am now facing a problem. where I have to convert an Array<Observable<T>> into an Observable<Array<T>> . I'll try to explain it with an example: - I have an Observable , which gives me a list of Users ( Observable<Array<User>> ) - The

How does the RxJs 5 share() operator work?

随声附和 提交于 2019-12-28 16:30:15
问题 Its not 100% clear for me how the RxJs 5 share() operator works, see here the latest docs. Jsbin for the question here. If I create an observable with a series of 0 to 2, each value separated by one second: var source = Rx.Observable.interval(1000) .take(5) .do(function (x) { console.log('some side effect'); }); And if I create two subscribers to this observable: source.subscribe((n) => console.log("subscriptor 1 = " + n)); source.subscribe((n) => console.log("subscriptor 2 = " + n)); I get

Best way to import Observable from rxjs

蓝咒 提交于 2019-12-28 01:42:23
问题 In my angular 2 app I have a service that uses the Observable class from the rxjs library. import { Observable } from 'rxjs'; At the moment I am just using Observable so that I can use the toPromise() function. I read in another StackOverflow question somewhere that importing in this way and also importing from rxjs/Rx will import a whole lot of unnecessary stuff from the rxjs library that will increase the page load times and/or the code base. My question is, what is the best way to import

Why is the new generics in TypeScript 2.4 causing this to fail?

六眼飞鱼酱① 提交于 2019-12-25 18:34:09
问题 So I understand that with TS 2.4 we get trickter generic checks. But what I don't understand is why now I get with this: getChannelBlockModels(i_campaign_timeline_chanel_id): Observable<List<CampaignTimelineChanelPlayersModel>> { return this.store.select(store => store.msDatabase.sdk.table_campaign_timeline_chanel_players) .map((campaignTimelineChanelPlayersModels: List<CampaignTimelineChanelPlayersModel>) => { return campaignTimelineChanelPlayersModels.filter(campaignTimelineChanelsModel =>

Angular resolver not resolving?

本小妞迷上赌 提交于 2019-12-25 17:04:34
问题 This is a demo of the problem: https://stackblitz.com/edit/angular-routing-with-resolver-observable?file=src%2Fapp%2Fpost-resolver.service.ts Switching out this.observeLoading$ with of(false) makes it work, so I think it has something to do with the fact that this.observeLoading$ is notified by a ReplaySubject that can provide more than one notification ... Here are more details: First this does resolve: async resolve( route: ActivatedRouteSnapshot) { const topic = await of(false).pipe(

How to call an async method in canActivate with angular?

谁说胖子不能爱 提交于 2019-12-25 09:29:12
问题 I am trying to implement a canActivate guard for an admin route in Angular 4.2.4. Based off this stack question here: canActivate Question, I think I'm doing everything correctly. But alas, I can't seem to get things to work. Here is the module guard: @Injectable() export class AuthGuard implements CanActivate { constructor(private _store: Store<AppState>, private router: Router, private czauth: CzauthService) { } canActivate(route: ActivatedRouteSnapshot):Observable<boolean>{ return this