rxjs

Why use NGRX instead of constructor injected services?

爷,独闯天下 提交于 2020-01-13 10:08:13
问题 Wondering why one would use NGRX or NGXS for an Angular app instead of constructor injected services to handle component IO? Is it only to ensure that component properties references are never mutated without switching out the entire property value reference or is there more to it? Altnernative to NGRX per the answer I developed: Slice. I believe it does everything NgRx / NgXS does (With the exception of a time machine - but this is easy to implement via delta notifications - already

Passing through multiple parameters to rxjs operator

雨燕双飞 提交于 2020-01-13 08:32:09
问题 Is there a more elegant way of doing the following? private getHeaders(): Observable<any> { let version; let token; return this.appInfo.getVersion() .pipe( tap(appVersion => version = appVersion), mergeMap(() => this.storage.get('access_token')), tap(accessToken => token = accessToken), mergeMap(accessToken => of(this.createHeaders(version, token))) ); } How can I more fluently remember the two return values of this.appInfo.getVersion() and this.storage.get('access_token') without writing

Observable vs asObservable()?

风格不统一 提交于 2020-01-13 02:39:08
问题 I'm new to Angular2 and I'm just curious to know That If I do a subscribe on _showNavBar or on showNavBarEmitter both works same(see below code i'm using). is there any difference? public _showNavBar: BehaviorSubject<boolean> = new BehaviorSubject<boolean>(null); public showNavBarEmitter: Observable<boolean> = this._showNavBar.asObservable(); 回答1: asObservable makes the original subject inaccessible for subscribers. This way you can limit who can only subscribe and who can also emit values.

Argument of type 'MonoTypeOperatorFunction<any>' is not assignable to parameter of type 'UnaryFunction<Observable<any>, Observable<any>>'

℡╲_俬逩灬. 提交于 2020-01-12 07:50:50
问题 i am trying to migrate from rxjs 5 to 6 but i am having difficulties. when i try this this._connectivity.isOnline().pipe(first()).subscribe((state) => { this.syncCheck(user.uid); }); i am getting this error Argument of type 'MonoTypeOperatorFunction<any>' is not assignable to parameter of type 'UnaryFunction<Observable<any>, Observable<any>>'. Types of parameters 'source' and 'source' are incompatible. Type 'import("/home/User/Desktop/projectname/node_modules/rxjs/Observable").Observable<any>

Angular 6 + RxJS 6.0 : How to push new element to array contained by Observable

怎甘沉沦 提交于 2020-01-12 07:28:08
问题 I am receiving data from firebase server in chunks while rendering that data requires a library which insists on observable contains Array. I am somehow unable to push a new data chunk to existing data chunk array contained by observable, From dataservice I am calling by subject's next and trying to add a new calEvent this.homeWorkerService.eventSubject.next(calEvent); In component, I have following code events$: Observable<Array<CalendarEvent<any>>>; and ngOnInit, I am supplying data to it

Error: Property timer doesn't exist on type typeof Observable

廉价感情. 提交于 2020-01-12 05:25:07
问题 The code is below import {Component} from 'angular2/core'; import {Observable} from 'rxjs/Rx'; @Component({ selector: 'my-app', template: 'Ticks (every second) : {{ticks}}' }) export class AppComponent { ticks =0; click(){ let timer = Observable.timer(2000,1000); timer.subscribe(t=>this.ticks = t); } } But i am getting an error. The error is in the following line: let timer = Observable.timer(2000,1000); The definition of error is "property timer doesn't exist on type typeof Observable" Why

ERROR in node_modules/rxjs-compat/operator/shareReplay.d.ts(2,10): error TS2305:

痴心易碎 提交于 2020-01-12 03:13:49
问题 I am trying to upgrade a basic angular skeleton app from angular 5 to angular 6 and here's the issue I am coming across when trying to run the app : ERROR in node_modules/rxjs-compat/operator/shareReplay.d.ts(2,10): error TS2305: Module '"C:/newAdmin/testing-front-end/admin-fe/node_modules/rxjs/internal-compatibility/index"' has no exported member 'ShareReplayConfig'. Here is my package.json : { "name": "admin-fe", "version": "0.0.0", "scripts": { "ng": "ng", "start": "ng serve", "build": "ng

ERROR in node_modules/rxjs-compat/operator/shareReplay.d.ts(2,10): error TS2305:

拟墨画扇 提交于 2020-01-12 03:13:42
问题 I am trying to upgrade a basic angular skeleton app from angular 5 to angular 6 and here's the issue I am coming across when trying to run the app : ERROR in node_modules/rxjs-compat/operator/shareReplay.d.ts(2,10): error TS2305: Module '"C:/newAdmin/testing-front-end/admin-fe/node_modules/rxjs/internal-compatibility/index"' has no exported member 'ShareReplayConfig'. Here is my package.json : { "name": "admin-fe", "version": "0.0.0", "scripts": { "ng": "ng", "start": "ng serve", "build": "ng

Angular 4. A series of http requests get cancelled

拜拜、爱过 提交于 2020-01-12 01:47:09
问题 When I try to make multiple http requests via http service in Angular 4, previous request get cancelled in Chrome (but they reach the server). Example: const obs1 = this.http.get(`${API_URL}/transitions`); const obs2 = this.http.get(`${API_URL}/states`); obs1.subscribe(); obs2.subscribe(); // this will cancel obs1's http request But if I replace .subscribe() to .publish().connect() like above, it will work correctly (no cancels) const obs1 = this.http.get(`${API_URL}/transitions`); const obs2

Angular2 Query Params Subscription Fires Twice

蓝咒 提交于 2020-01-11 18:46:35
问题 Trying to handle an OAuth login scenario where if the user lands on a page with authorization_code in the query string, we process the token and continue or if they land on the page without that, we check local storage for their existing token, make sure it's still valid and either redirect to login or continue, based on its validity. The problem is that where we're checking for the existence of the authorization_code query string param, the subscription is firing twice. The first time it is