rxjs

Using observable talk to other component in angular2, not receiving coming value

非 Y 不嫁゛ 提交于 2019-12-13 05:25:58
问题 I have this structor app/ --pages/ ----pages.component.ts --channel/ ----shared/ ------assignPlaylist.modal.ts Inside the pages.component.ts, I have a variable called playlist export class PagesComponent { @Input() platform: Platform; @Output() onPlaylistsChange: EventEmitter<Playlists>; currentPageName: string; currentPage: Page; pages: Array<Page>; playlists: Playlists; } In assignPlaylist.modal.ts, I make an http post method and it returns a new playlists, I need to use that returned

pipe operator not behaving as expected RXJS

醉酒当歌 提交于 2019-12-13 05:06:53
问题 Please look at my component below the purpose to is to listen on changes to an input, which it does and then emit the value to the parent component. I created a pipe to only emit every so often and therby minimize the calls to the api, for some reason even though I can see through various console.log statements that it goes in the pipe, it emits the value on every change. What is it that I am missing: import {ChangeDetectionStrategy, Component, EventEmitter, Input, OnChanges, OnInit, Output,

Handling error with rxjs not compatible with interceptors

做~自己de王妃 提交于 2019-12-13 04:26:31
问题 Based on this question Angular intercepting http errors that is resolved, I'm facing a huge philosophical issue. All my services look like this: public getSomething(): Observable<Something> { return this.http .get<Something>(url) .pipe( map(res => res.data), catchError((e): Observable<any> => of(e)) ); } If my authentication token is invalid / expired, the service catches the error. I can call log out right there. However, if I have a lot of services, I have to repeat this process that many

RxJs: Calculating observable array length in component

我的未来我决定 提交于 2019-12-13 03:57:19
问题 I have an observable array, purchases$ . In my angular 2 component I'd like to calculate the length of the array. I worry that the observable is never complete and thus my subscriptions end up piling up. If I do the following will the subscription be complete? this.purchases$.subscribe((val) => { val.length > 0 ? this.purchaseType = 'initial' : this.purchaseType = 'additional' }) Once I have an initial value I am happy to unsubscribe. Can I simple add .unsubscribe() to the end? 回答1: What you

Angular 5 intercept - requests are duplicated

狂风中的少年 提交于 2019-12-13 03:56:04
问题 I am using an interceptor with HttpInterceptor in angular 5 and I have a problem with rxjs where all my http requests are duplicated. import { Router } from '@angular/router'; import { Injectable, ApplicationRef } from '@angular/core'; import { HttpEvent, HttpInterceptor, HttpHandler, HttpRequest, HttpResponse } from '@angular/common/http'; import { Observable } from 'rxjs/Rx'; import 'rxjs/add/observable/throw'; import 'rxjs/add/operator/catch'; import 'rxjs/add/observable/empty'; import {

How to build a service that gets values async but also perfoms tasks on that data, like filtering?

白昼怎懂夜的黑 提交于 2019-12-13 03:54:19
问题 I have a service " provided in root " that: gets data once from an API should handle a mapping on that data should provide that data to other components if needed This data doesn't need to be reloaded throughout the lifecycle of the app. It's only reloaded when the user refreshes the browser. All of the data is going to be used at some point - so it makes no sense to make http requests on each getOneById() . A filter is faster in this case. The mockup of the service looks something like this:

Redux Observable: If the same action is dispatched multiple times, how do I cancel one of them?

白昼怎懂夜的黑 提交于 2019-12-13 03:49:16
问题 Say, I have this epic: export const getUserEpic = action$ => action$ .ofType(t.GET_USER) .mergeMap(action => Observable .from(query.findUser(action.uid)) .map(user => ({ type: t.GET_USER_SUCCESS, user })) .takeUntil(action$.ofType(t.GET_USER_CANCELLED)) Then, somewhere I dispatched t.GET_USER multiple times: dispatch({ type: t.GET_USER, uid: 'uid1' }) dispatch({ type: t.GET_USER, uid: 'uid2' }) dispatch({ type: t.GET_USER, uid: 'uid3' }) How do I cancel one of them? For example: dispatch({

Returning data from AngularJS service to controller with RxJS

二次信任 提交于 2019-12-13 03:47:07
问题 I am using web socket to connect to server. I am calling a service from controller. The request is going to server and response is coming back to service which is in app.js file. Now I need the response in controller file. Can any one help me how to send the response from app.js to controller from where the request is made. app.js app.factory('MyService', ['$rootScope', function($rootScope) { var Service = { }; // Create our websocket object with the address to the websocket var ws = new

I can't get data when I subscribe to a subject as observable (rxJS 5.5.2)

三世轮回 提交于 2019-12-13 03:37:30
问题 I found this great code to display alert in my component but, since Angular 5.2.0 and rxJS 5.5.2, I can't get my alerts. I put some console log eveywhere to understand what is the problem but I didn't find it. I think the problem is about the subject asObservable : I can subscribe to it but there is no data. alert.service.ts import { Injectable } from '@angular/core'; import { Router, NavigationStart } from '@angular/router'; import { Observable } from 'rxjs'; import { Subject } from 'rxjs

RxJS - Create Observable from an EventEmitter's multiple events

余生颓废 提交于 2019-12-13 03:35:46
问题 I have a node.js EventEmitter which raises the following events: error , message . Is there a straight forward way I can create an RxJS Observable from it? i.e next() called on message and error() called on error . 回答1: You can create it like this: const obs$ = Observable.create(observer => { emitter.on('message', val => observer.next(val)); emitter.on('error', err => observer.error(err)); }); As an alternative, you can do this by constructinng and chaining observables like this, but it's