rxjs

Cancel flatMap observable call chain

懵懂的女人 提交于 2019-12-12 12:05:00
问题 I am using angular 5 and rxjs. I am making 2 service calls, one dependent on others results. I am doing it using flatMap. I am also using takeUntil so that I can abort operation at any given point. My code looks like below: this.myservice.api1(param1).pipe(takeUntil(this.destroyed$), finalize(() => { //do something after both api calls are completed }, flatMap((result1) => { //do some operation and create object x(this.objx) return this.myservice.api2(param1); }) ).subscribe((result2) => { /

How do I trace an `EmptyError: no elements in sequence` bug in an angular project

人走茶凉 提交于 2019-12-12 11:25:56
问题 I'm working on an Angular project that's throwing an error: core.js:1350 ERROR Error: Uncaught (in promise): EmptyError: no elements in sequence but I can't seem to trace it to any of my app source code. The stack trace all points to rxjs classes. Can anyone tell me how I can debug this error so that I can get to the real error in the code? core.js:1350 ERROR Error: Uncaught (in promise): EmptyError: no elements in sequence EmptyError: no elements in sequence at new EmptyError (EmptyError.js

switchMap does not seem to complete when the inner observable completes

心不动则不痛 提交于 2019-12-12 11:21:55
问题 I'm still a noob when it comes to RxJS but here's a JSBin of what I am trying to do. https://jsbin.com/wusalibiyu/1/edit?js,console I have an observable 'a' (in my case it's the current active connection) which emits a new object whenever the connection reconnects. It's an observable itself because it can re-emit a new value. I now want an observable that completes whenever an action is executed on the current connection. That action notifies it is done when the observable for it completes.

Angular 2 AsynPipe isn't working with an Observable

烈酒焚心 提交于 2019-12-12 11:06:36
问题 I'm getting the following error: EXCEPTION: Cannot find a differ supporting object '[object Object]' in [files | async in Images@1:9] Here's the relevant part of the template: <img *ngFor="#file of files | async" [src]="file.path"> Here's my code: export class Images { public files: any; public currentPage: number = 0; private _rawFiles: any; constructor(public imagesData: ImagesData) { this.imagesData = imagesData; this._rawFiles = this.imagesData.getData() .flatMap(data => Rx.Observable

Angular 2 trying to implement Observables in services

旧巷老猫 提交于 2019-12-12 11:01:54
问题 Im trying to send data from one component to other using observable. Here I'm implementing observable in service like this... import { Injectable } from '@angular/core'; import { Observable } from 'rxjs/RX' @Injectable() export class SelectedItemService { stream1$:Observable<any>; selectedItem:JSON; stream1$= new Observable(observer=> setTimeout(() => { observer.next(this.selectedItem); }, 3000);) } and my parent Component is initializing data to a service in onselect() like below : import {

Is ReplaySubject(1) the same as AsyncSubject()?

怎甘沉沦 提交于 2019-12-12 10:01:42
问题 I'm currently using this to perform notifications: /** * Create notifications that broacast * the entire set of entries. */ protected notify = new ReplaySubject<E[]>(1); IIUC I can switch out the ReplaySubject<E[]>(1) with AsyncSubject<E[]>() ? Would this be an apple to apple switch or might here be semantic differences? 回答1: No, they're very much not the same. ReplaySubject(1) will always replay the latest emission no matter when the observer subscribes. It can emit any number of times.

RXJS: Adding a function to Observable to execute when subscribed to (defer)

牧云@^-^@ 提交于 2019-12-12 09:56:59
问题 Adding a function to Observable to execute when subscribed to (defer) I have an Observable made from events. In this case, Bluetooth notifications. I want to run a function (startNotifictions) only when someone is subscribing to that Observable. This code did work, on previous versions. It is with Ionic3 framework. It added a new operator, that ran when subscribed. Now the transpiler has a problem with the types, complaining twice, that the .doOnSubscribe is not available on typedef

RxJS: distinguish single click from drag

做~自己de王妃 提交于 2019-12-12 09:39:43
问题 I have an AngularJS component that should react to either a single click or a drag (resizing an area). I started to use RxJS (ReactiveX) in my application, so I try to find a solution using it. The Angular side of the request is minor... To simplify the problem (and to train myself), I made a slider directive, based on the rx.angular.js drag'n'drop example: http://plnkr.co/edit/UqdyB2 See the Slide.js file (the other code is for other experiments). The code of this logic is: function(scope,

do (tap) vs subscribe

一曲冷凌霜 提交于 2019-12-12 09:34:35
问题 Edit: Prior to RxJs 6, tap was called as do . Updated title to reflect tap too. I would like to understand what is the best practice of using .subscribe and .do methods of Observables. For example if I need to do some job after initial data is loaded from server const init$: Observable<MyData> = this._dataService.getData(); init$ .do((initialData: MyData) => { this.data = initialData; // at this step I am initializing the view }) .switchMap(() => loadExtraData) .subscribe((extraData) => {

How to use RxJs distinctUntilChanged?

一个人想着一个人 提交于 2019-12-12 09:29:29
问题 I'm getting started with RxJs (using the v5 beta), but somehow I can't figure out how to work with distinctUntilChanged . The output from the code below if I run it in babel-node is [ 'a', 1 ] { key: 'a', state: 1 } Next: { value: 42 } Completed That is not what I would expect. Why is only one entry passing distinctUntilChanged ? I would expect the output to be [ 'a', 1 ] [ 'a', 0 ] [ 'a', 1 ] { key: 'a', state: 1 } { key: 'a', state: 2 } { key: 'a', state: 0 } { key: 'a', state: 1 } Next: {