rxjs6

Subject Subscription is triggered twice when I call .next() once in Angular app

谁说我不能喝 提交于 2019-12-24 03:41:23
问题 i'm trying to create a reusable Modal component. in a ModalService i have a Subject, and a method that that calls next() on the subject. The ModalComponent subscribes to that subject, but whenever the method in the service is being called, the next function of the observer gets triggers twice. Anyone know what causes this? export class ModalService { openModal = new Subject(); constructor() { } open(cmp) { this.openModal.next(cmp); } } Modal Component: export class ModalComponent implements

Rxjs 6: using catchError() gives You provided 'undefined' where a stream was expected. You can provide an Observable, Promise, Array, or Iterable

瘦欲@ 提交于 2019-12-23 19:36:08
问题 I'm using the new syntax to comply with RxJS 6 pipe() . Also using Angular 6. I have a service that handles http requests, and it pipes map and catchError to display a toast in case of connection error. Nevertheless, If I add catchError I get in console You provided 'undefined' where a stream was expected. You can provide an Observable, Promise, Array, or Iterable. getDataHttpRequest(url, returnType) { return this.http.get(url, this.getRequestOptions()) .pipe( map((response) => { if(response)

Returning caught error observable from catchError in HttpInterceptor causes error loop

自闭症网瘾萝莉.ら 提交于 2019-12-23 09:24:53
问题 I have a simple interceptor that handles requests and catches any http error using RXJS catchError. The second argument received in catchError is the caught observable. I want to, in some cases, return this error and let it propagate up to the error handler in the subscribe function. The problem is that returning th caught error causes an infinite loop (as seen in the example: https://stackblitz.com/edit/angular-u4gakr) The intercept function in the interceptor where the catchError is stuck

Property 'map' does not exist on type 'Observable' after upgrading rxjs to 6

僤鯓⒐⒋嵵緔 提交于 2019-12-23 03:39:10
问题 I upgraded my Angular application from version 5.2 to 6.0 with the instructions from https://update.angular.io. Now my Angular application doesn't build because of the "rxjs-5-to-6-migrate" migration: ERROR in bla.ts: error TS2339: Property 'map' does not exist on type 'Observable'. I have the following imports: import { Observable } from 'rxjs/observable'; import { of } from 'rxjs/observable/of'; import { map } from 'rxjs/operators'; If I change the imports like this it works: import {

Fire multiple actions and wait for them to resolve RxJS / Redux Observables

别等时光非礼了梦想. 提交于 2019-12-23 01:52:07
问题 I have an action that I want to use to initialise my app, I want to create an epic for this action and then fire multiple other actions off the back of this, wait for them to all complete and there fire another action. I had a look at other questions and it's pretty similar to this one I've tried this approach and for me, it doesn't work, it fires the APP_INIT action then but then fails to fire any of the other actions in the sequence. Is anyone able to help? import { of } from 'rxjs'; import

How to fix “ Property 'wheelDelta' does not exist on type 'WheelEvent' ” while upgrading to angular 7,rxjs6?

大城市里の小女人 提交于 2019-12-22 08:39:33
问题 I'm upgrading to angular7 with rxjs6: in mouseWheelEvent type I am getting "Property 'wheelDelta' does not exist on type 'WheelEvent'" . Do we have any alternative for wheelDelta ? mouseWheelFunc(event: MouseWheelEvent): void { // var event = window.event || event; // old IE support let delta = Math.max(-1, Math.min(1, (event.wheelDelta || -event.detail))); if ( delta > 0) { this.mouseWheelUp.emit(event); } else if ( delta < 0) { this.mouseWheelDown.emit(event); } // for IE event.returnValue

How to keep observable alive after error in RxJS 6 and Angular 6

限于喜欢 提交于 2019-12-21 21:41:24
问题 Can anyone help with the scenario where this._getReactions$.next() not working whenever this.http.get(...) gets an error. I want to keep observable alive to take the next input. private _getReactions$: Subject<any> = new Subject(); constructor() { this._getReactions$ .pipe( switchMap(() => { return this.http.get(...) // http request }), catchError(error => { console.log(error); return empty(); }) ) .subscribe(data => { console.log(data) //results handling }); } onClick() { this._getReactions$

mergeMap does not exist on type observable

若如初见. 提交于 2019-12-21 05:05:03
问题 I am trying to use mergeMap in rxjs6 and i am getting this error: Property 'mergeMap' does not exist on type 'Observable<{}>' I have tried import 'rxjs/add/operator/mergeMap'; and it is not working. What am i doing wrong? import {from, Observable} from 'rxjs'; export class Test { public doSomething(): Observable<any> { return from(...).mergeMap(); } } 回答1: That's correct, the "patch" style of operators has been removed since RxJS 6. You should better update your code to use only "pipeable"

How do I mock RxJs 6 timer?

不问归期 提交于 2019-12-18 15:51:24
问题 We've recently updated from Angular 5 to Angular 6, and with it RxJs 6. As part of the migration, the timer usage has changed from: Observable.timer() to timer() There are a number of places in our tests where we mock timer observables with the following pattern. let timerObserver: Observer<any>; beforeEach(() => { spyOn(Observable, 'timer').and.returnValue(Observable.create( ((observer: Observer<any>) => { timerObserver = observer; }) )); }); it(`should not have any notifications by default`

I dont get rxjs 6 with angular 6 with interval, switchMap, and map

只谈情不闲聊 提交于 2019-12-18 12:12:51
问题 I want to update my rxjs code to 6 got I don't get it. Before I had the below that wouth poll for new data every 5 seconds: import { Observable, interval } from 'rxjs'; import { switchMap, map } from 'rxjs/operators'; var result = interval(5000).switchMap(() => this._authHttp.get(url)).map(res => res.json().results); Now...of course, it's broken and the documentation leaves me nowhere to go. How do I write the above to conform to rxjs 6? Thanks 回答1: The code should be something like the