rxjs

Group/sum property values inside an array of objects(json) using Angular 4 Pipes or Rxjs operators

孤人 提交于 2019-12-12 17:36:17
问题 The response from my http call is an array of company objects like this: response = [{ "name": "CompanyName1", "registrations": [ { "country": "en", "register": "registerType1", "amount": 2 }, { "country": "wa", "register": "registerType2", "amount": 1 },{ "country": "en", "register": "registerType1", "amount": 3 }, { "country": "sc", "register": "registerType3", "amount": 2 }, { "country": "wa", "register": "registerType3", "amount": 2 } ] }, { "name": "CompanyName2", "registrations": [ {

You provided an invalid object where a stream was expected. You can provide an Observable, Promise, Array, or Iterable

六眼飞鱼酱① 提交于 2019-12-12 17:26:18
问题 Say I have the following function references: const externalRequests = (params) => Rx.Observable.zip( externalApi1(params), externalApi2(params) ) and const internalDB = (params) => Rx.Observable.fromPromise(getStuffFromDB(params) externalRequests returns something of the shape: { _isScalar: false, source: { _isScalar: false, source: { _isScalar: false, array: [Object], scheduler: undefined }, operator: { project: [Object] } }, operator: undefined } and can be .subscribe 'd to. internalDB ,

Using `retryWhen` in http requests

≡放荡痞女 提交于 2019-12-12 16:34:32
问题 I have extended Http class to set default headers and handle errors for all the requests inside an angular2 app, and I would like to use retryWhen() to retry the requests on certain errors. On which errors should retryWhen retry the request and on which errors should it stop? @Injectable() export class WpHttp extends Http { constructor(backend: ConnectionBackend, defaultOptions: RequestOptions, private wpService: WpService) { super(backend, defaultOptions); } get(endpoint: string, args?:

Angular rxjs Observable.interval() not triggering properly on background tabs in Chrome

柔情痞子 提交于 2019-12-12 15:35:58
问题 I am writing angular2 application with interval timers implemented via RxJs observables, and just noticed the strange behaviour of Observable.interval() and Observable.timer() in Chrome browser when tab is in background. Angular component should once every second print number of seconds in console, but on background tabs, this is not working as intended - function triggers every x+1 seconds, where x is interval specified explicitely in the interval funciton Angular component code: ngOnInit()

Property 'catchError' does not exist on type 'Observable<HttpEvent<any>>'

时光怂恿深爱的人放手 提交于 2019-12-12 15:20:28
问题 Went from angular 5 to 6(using angular 6 & rxjs 6), getting the following two errors in my linter. Anybody have any ideas, please and thank you. [ts] 'catchError' is declared but its value is never read. [ts] Property 'catchError' does not exist on type 'Observable<HttpEvent<any>>'. import { Injectable, Injector } from '@angular/core'; import { HttpEvent, HttpInterceptor, HttpHandler, HttpRequest } from '@angular/common/http'; import { catchError } from 'rxjs/operators'; import { Observable }

How to prevent AsyncSubject from completing when the last observer unsubscribes

北城以北 提交于 2019-12-12 15:15:06
问题 The AsyncSubject becomes observable when the last subject observer unsubscribes from the subject. Here is the quote: When it’s done, it’s done. Subjects cannot be reused after they’re unsubscribed, completed or errored. Here is the demo: const ofObservable = Rx.Observable.of(1, 2, 3); const subject = new Rx.AsyncSubject(); ofObservable.subscribe(subject); subject.subscribe((v) => { console.log(v); }); subject.unsubscribe((v) => { console.log(v); }); // here I'll get the error "object

How to sort Firebase observable list based on the duplicated value using RXJS operators

柔情痞子 提交于 2019-12-12 13:52:38
问题 I'm using the rxjs operators to handle the firebase observable lists. I need to sort distinct list based on the duplicated value (certain id). this is my code: this.places$ .flatMap((x)=>{ console.log(x) return x; }) .distinct((places:any)=>{ console.log(places.googleId) return places.googleId; }) .subscribe(snap=>{ this.tempArray.push(snap); }) this is the log of (places.googleId) so i need to sort this ids or the list according of the most duplicated number to be for example 1

RxJS fromEvent operator with output EventEmitter in Angular

偶尔善良 提交于 2019-12-12 13:19:35
问题 Say there's ChildComponent which emits out an event called someEvent . Obviously, I can catch the event in ParentComponent declaring like, <child-component (someEvent)="onSomeEvent($event)"></child-component> and handle it with the method onSomeEvent in ParentComponent . But what I'm trying is that I want to handle the event with fromEvent operator in RxJS. I've tried fromEvent(this.childComponent.nativeElement, 'someEvent') after getting the ElementRef of the ChildComponent with @ViewChild .

Empty subscribe on valueChanges in Angular2

匆匆过客 提交于 2019-12-12 12:45:25
问题 I have this weird case, a subscribe that never fires if left empty. This doesn't work: this.formGroup.get('unitCount').valueChanges .do(value => console.log(value)) .subscribe(); When this works fine: this.formGroup.get('unitCount').valueChanges .do(value => console.log(value)) .subscribe(() => true); Here I used () => true , but it could anything, false , void 0 , even an empty object {} Why can't I leave the subscribe() empty? 回答1: You probably have a older version of RxJS 5. This was a bug

Use Observable for AWS cognito callback

风流意气都作罢 提交于 2019-12-12 12:24:58
问题 How can I turn the signup callback into an Observable, conforming to the Angular 2 convention? This is what the callback structure is like userPool.signUp(this.artist.email, this.artist.password, attributeList, null, function(err, result) { if (err) { alert(err); return; } let cognitoUser = result.user; console.log(JSON.stringify(result)); console.log('user name is ' + cognitoUser.getUsername()); }); 回答1: There is an RxJS static operator for just that purpose: bindNodeCallback. It will