rxjs

Keep list updated with Ionic 2 / Angular 2

守給你的承諾、 提交于 2019-12-06 19:23:25
I have an application developed with Ionic 2 that uses Angular 2. I want to update the list of my component in two ways. Automatic - Refresh if there is no update or if the last update was more than 30 minutes ago. Manual - If the user does not want to wait until the next update, he can update manually at any time. When the user leaves the page cancel the automatic refresh and when he comes back re-initialize. I do not want to update immediately when the user enters the page, but only when it completes 30 minutes since the last update. What would be the best way to achieve this? I wonder if

angular2 Observable Property 'debouceTime' does not exist on type 'Observable<any>'

余生颓废 提交于 2019-12-06 18:35:03
问题 I use "angular2 webpack" and "angular2/form,Observable" , but met an error ,need help .. There is a custom form validator -- import {Observable} from 'rxjs/Rx'; import {REACTIVE_FORM_DIRECTIVES,FormControl, FormGroup, Validators} from '@angular/forms'; emailShouldBeUnique(control:FormControl) { return new Observable((obs:any)=> { control.valueChanges .debouceTime(400) .distinctUntilChanged() .flatMap(term=>return !this.userQuery.emailExist(term)) .subscribe(res=> { if (!res) {obs.next(null)}

How to make countdown timer with RxJS Observables?

我们两清 提交于 2019-12-06 18:16:23
问题 I'm struggling to create a countdown timer using Observables, the examples at http://reactivex.io/documentation/operators/timer.html do not seem to work. In this specific example the error related to timerInterval not being a function of the Observable returned from timer. I have also been experimenting with other approaches and the best I've come up with is: Observable.interval(1000).take(10).subscribe(x => console.log(x)); The problem here is it counts up from 0 to 10 and I want a countdown

Combining Observables when both change simultaneously

℡╲_俬逩灬. 提交于 2019-12-06 17:25:46
I am trying to integrate ReactiveX into my GUI using RxPY. This is a general ReactiveX question. Say I have a visualization that depends on multiple Observable streams using combine_latest(stream1, stream2, plot_function) . This works great when one Observable changes, like when the user modifies a value; the visualization updates using the new values. However, sometimes both Observables are updated simultaneously, like when the user loads data for both streams from a single file. Technically, one Observable will be updated before the other (whichever comes first in the import function). As a

RxJS distinctUntilChanged - object comparsion

試著忘記壹切 提交于 2019-12-06 17:06:04
问题 I have stream of objects and I need to compare if current object is not same as previous and in this case emit new value. I found distinctUntilChanged operator should do exactly what I want, but for some reason, it never emit value except first one. If i remove distinctUntilChanged values are emited normally. My code: export class SettingsPage { static get parameters() { return [[NavController], [UserProvider]]; } constructor(nav, user) { this.nav = nav; this._user = user; this

RxJS alternative to doing a Promise.resolve?

谁说我不能喝 提交于 2019-12-06 16:34:16
问题 What is the equivalent in RxJS to Promise.resolve ? I know I can do Observable.fromPromise(Promise.resolve(someValue)); but there has to be a cleaner way. 回答1: Observable.of is what you are looking for (see this plunk): // You might need to add this import in RxJS versions earlier than 5 import 'rxjs/add/observable/fromArray'; // ... or this line in RxJS 5+ import 'rxjs/add/observable/of'; if (me.groups) { return Observable.of(me.groups); } 来源: https://stackoverflow.com/questions/34616540

Rxjs Observable Lifecycle

若如初见. 提交于 2019-12-06 15:36:48
If I am ever working with rxjs , I normally, in my component file, keep track of all of my subscriptions by pushing said subscriptions into a Subscription array: private subcriptions: Subscription[]; this.subscriptions.push(this.myObservableOne.subscribe(...)); this.subscriptions.push(this.myObservableTwo.subscribe(...)); public ngOnDestroy(): void { this.subscriptions.forEach(s => s.unsubscribe()); } Now, I am running into something that I thought was interesting. If I instead need to subscribe to an Observable from a service: this.myService.myObservable.subscribe(...) Who owns the

In Rxjs scan operator, is it possible to remove an item from the internal accumulator created by the scan operator?

自作多情 提交于 2019-12-06 15:08:27
Based on this question here , I am using the Rxjs scan operator to keep track of all of the observables that get emitted in an the accumulator array, and then each new incoming value I am adding it to that internal accumulator array created by the scan operator and then I am emitting the single array. This allows me to bind to that array observable with the async pipe in the template and display previews of images user uploaded. However if I want to implement the remove or undo functionality, I have need access to that array to be able to remove an item from it. This is my scan operator:

Angular - Catching error after all HTTP retry failed

扶醉桌前 提交于 2019-12-06 14:54:22
I am using Angular Service to get data from my API . I implemented retry feature in case of fetching data fails. Now i need to handle the error when all the retries wear out, but im not able to catch it. Following is my code, public getInfoAPI(category:string, id:string = "", page:string = "1", limit:string = "10"){ var callURL : string = ''; if(!!id.trim() && !isNaN(+id)) callURL = this.apiUrl+'/info/'+category+'/'+id; else callURL = this.apiUrl+'/info/'+category; return this.http.get(callURL,{ params: new HttpParams() .set('page', page) .set('limit', limit) }).pipe( retryWhen(errors =>

RxJs Subject error - cannot read property 'subscribe' of undefined

吃可爱长大的小学妹 提交于 2019-12-06 14:26:01
问题 In my service method that returns Observable I'm trying to notify the component via Subject that an action completed. completed: Subject<boolean> constructor(private http: Http) { } loadItems(): Observable<FrontItemDto[]> { return this.http.get ( `${ServiceSettings.ApiUrl}/front` ) .map ( res => { res.json (); if ( res.json () ) { this.completed.next ( true ); } } ) .catch ( (error: any) => Observable.throw ( error.json ().error || 'Server error' ) ); } This is how the component is listening