rxjs

Property 'connect' does not exist on type 'Observable<any>' | RXJS multicast

北城余情 提交于 2019-12-23 09:04:16
问题 I have an Observable that produce the unicast value(individually for all observers). But when i am going to convert into multicast using RxJs multicast operators then it return the following error. Property 'connect' does not exist on type 'Observable' Unicast (Working Code) - let source4$ = interval(1000).pipe(take(4)); source4$.subscribe(val => { console.log(`Observer 1: ${val}`); }); setTimeout(function() { source4$.subscribe(val => { console.log(`Observer 2: ${val}`); }); }, 1000);

Observable Map function not running (Angular2, http)

我怕爱的太早我们不能终老 提交于 2019-12-23 08:51:42
问题 Update The issue seems to be that the map function is not run on a "failed" request. This means that if the API I'm talking to returns a 422 Validation Failed error (or other 4xx errors) Angular will treat this as a failure and cause the Observer to run the subscribed error callback, skipping the map function in the process. Is it possible to force Angular to treat certain 4xx errors as successful requests, or force the map function to run even when an Observable returns an error? I have the

Making an Observable from a callback

坚强是说给别人听的谎言 提交于 2019-12-23 08:47:36
问题 I have an auth guard that needs an asynchronous response true/false when the site is visited and the user is already logged in. I'm using Firebase's onAuthStateChanged (link to docs) and it uses a callback function. How can I turn my isLoggedIn() method into something that can return Observable<boolean> ? Typscript: get isLoggedIn(): Observable<boolean> { // want something like this: return Observable.fromCallback(firebase.auth().onAuthStateChanged).map(user => !!user); // this returns () =>

Difference between catch and onErrorResumeNext

本小妞迷上赌 提交于 2019-12-23 08:33:14
问题 In RxJS, there seems to be very little difference between an Observable instance's catch method and onErrorResumeNext method, besides the fact that onErrorResumeNext concatenates the original Observable with the Observable parameters whether an error happens or not. If that's the case, isn't the naming a bit confusing? Because in case there is an error , onErrorResumeNext works exactly the same way than catch does: var testObservable = Rx.Observable.return(1).concat(Rx.Observable.throw("Error

Observable.fromEvent - RXJS

旧城冷巷雨未停 提交于 2019-12-23 07:52:52
问题 I'm trying to create an Observable from an input event. I have already tried almost everything and I can not import "fromEvent". This is my code. I am using angular 6.0.1 and RXJS 6.1.0 error TS2339: Property 'fromEvent' does not exist on type 'typeof Observable'. import { Directive, EventEmitter, Input, Output, ElementRef, ViewChild, AfterViewInit } from '@angular/core'; import { NgControl } from '@angular/forms'; import { distinctUntilChanged } from 'rxjs/internal/operators

Observable.fromEvent - RXJS

夙愿已清 提交于 2019-12-23 07:52:22
问题 I'm trying to create an Observable from an input event. I have already tried almost everything and I can not import "fromEvent". This is my code. I am using angular 6.0.1 and RXJS 6.1.0 error TS2339: Property 'fromEvent' does not exist on type 'typeof Observable'. import { Directive, EventEmitter, Input, Output, ElementRef, ViewChild, AfterViewInit } from '@angular/core'; import { NgControl } from '@angular/forms'; import { distinctUntilChanged } from 'rxjs/internal/operators

Is there an RX method which combines map and filter?

假如想象 提交于 2019-12-23 07:49:24
问题 I'm new to RxJS. I know I could just .filter and .map an observable to get the change I'm looking for. But, is there any method which combines the two into one function? 回答1: Yes there is. FlatMap. Suppose you have an Observable of numbers (1, 2, 3, 4, 5, ...) and you want to filter for even numbers and map them to x*10. var tenTimesEvenNumbers = numbers.flatMap(function (x) { if (x % 2 === 0) { return Rx.Observable.just(x * 10); } else { return Rx.Observable.empty(); } }); 来源: https:/

Rxjs observable wait until some condition is met

蓝咒 提交于 2019-12-23 07:46:12
问题 I have the following retry logic to retry an operation. It works fine for single request. For multiple on going requests, I would like to wait for existing retry logic to complete before retrying. handleError(errors: Observable<any>) { const retryCountStart: number = 1; // wait if there is any existing operation retrying // once it is complete, continue here return errors .mergeScan<any, any>( (retryCount: any, err: any) => { if (retryCount <= 5) { return Observable.of(retryCount + 1); } }

How to convert an Observable into a BehaviorSubject?

久未见 提交于 2019-12-23 07:41:29
问题 I'm trying to convert an Observable into a BehaviorSubject. Like this: a$ = new Observable() b$ = BehaviorSubject.create(new BehaviorSubject(123), a$) // 🔴 I have also tried: a$ = new Observable() b$ = new BehaviorSubject(a$, 123) // 🔴 And: a$ = new Observable() b$ = a$.asBehaviorSubject(123) // 🔴 And: a$ = new Observable() b$ = a$.pipe( toBehaviorSubject(123) ) // 🔴 But none of these works. For now I have to implement like this: a$ = new Observable() b$ = new BehaviorSubject(123) a$

BehaviourSubject's distinctUntilChanged() is not a function

自作多情 提交于 2019-12-23 07:38:43
问题 I am new to Rxjs I am trying understand BehaviourSubject below is my code export interface State { items: Items[] } const defaultState = { items: [] }; const _store = new BehaviorSubject<State>(defaultState); @Injectable() export class Store { private _store = _store; changes = this._store.distinctUntilChanged() .do(() => console.log('changes')); setState(state: State) { this._store.next(state); } getState() : State { return this._store.value; } purge() { this._store.next(defaultState); } }