rxjs

rxjs: EmptyError: no elements in sequence

怎甘沉沦 提交于 2019-12-08 16:31:33
问题 I am getting an error 'EmptyError: no elements in sequence' error when I go to localhost:8080. I have seen the thread Angular 5 EmptyError: no elements in sequence while making child routes but none of the answers seem to apply. I have "rxjs": "^5.5.6" and in my routes, I tried adding pathMatch: 'full', but the error is still displayed. Extract of my app-routing-module.ts const routes: Routes = [ { pathMatch: 'full', /* added recently for test purposes*/ path: '', component: RootComponent,

Converting RxJS Observable to a Promise

╄→гoц情女王★ 提交于 2019-12-08 16:27:43
问题 I'm trying to store data in local storage using multiple http calls. I use forkJoin to wait until all of the calls have been completed and then I want to resume my Promise.then call chain. How do I do this? updateCache() { var cachesToUpdate; return this.fetchServerTimestamps() .then(res => { var localTimestamps = this.getLocalTimestamps(); var serverTimestamps = this.getServerTimestamps(); //Compare timestamps and decide which cache data types to update cachesToUpdate = this.cacheTypes

rxjs using promise only once on subscribe

ε祈祈猫儿з 提交于 2019-12-08 15:31:43
问题 I wanted to use rxjs for the first time but am a bit stucked 'cause it doesn't behave exactly like I want it to: In my scenario I want to create an observable from a promise. But I want the promise only being called once (not on every subscription) and I want it not being called on creation time (defer the call to the first subscription). First I tried this: var source = Rx.Observable.fromPromise(_this.getMyPromise()) which causes a call to the getMyPromise function right on creation time.

Angular2 Observables — Replay

别来无恙 提交于 2019-12-08 15:20:41
问题 I am trying to set up an Angular2 Observable that will replay the latest value. import {Injectable} from 'angular2/core'; import {Observable} from 'rxjs/Observable'; @Injectable() export class RefinementService { refining: any; private r: any; constructor() { this.refining = new Observable(observer => this.r = observer).replay(1); } } I continually get errors stating: Property 'replay' does not exist on type Observable<{}>. and this.refining.replay is not a function Has anyone successfully

Wait on RxJs.Subscriptions to finish before resuming

╄→尐↘猪︶ㄣ 提交于 2019-12-08 14:50:49
问题 In my Angular 2 app I need to make a series of http request. I have two services, A & B, that each make request, A.get() and B.get() , that gets data from the API and stores them in the their service. These two can be called at the same time, however I have a third request doSomething() that depends on the results of A.get() and B.get() . Since both A.get() and B.get() are storing their responses locally their return value ends up be the RxJs Subscription. Like so: class A{ public data;

Deferred pattern with RxJS 5 observables

醉酒当歌 提交于 2019-12-08 14:47:12
问题 For arbitrary promise implementation, the deferred pattern (not to be confused with antipattern) may may look like: const deferred = new Deferred; ... // scopes where `deferred` object reference was passed before promise settlement deferred.promise.then((result) => { ... }, (error) => { ... }); ... deferred.resolve(...); // doesn't affect promise state deferred.reject(); ... // after promise settlement deferred.promise.then((result) => { ... }, (error) => { ... }); deferred object holds

How to pass observable value to @Input() Angular 4

放肆的年华 提交于 2019-12-08 14:35:59
问题 I am new to angular and I have the following situation which is I have a service getAnswers():Observable<AnswerBase<any>[]> and two components that are related to each other. online-quote dynamic-form online-quote component calls the service getAnswers():Observable<AnswerBase<any>[]> in its ngOnInit() method and the result of this, is passed to the component dynamic-form . To illustrate the situation this is the code of my two components: online-quote.component.html: <div> <app-dynamic-form

How do I conditionally buffer key input based on event in RxJs

∥☆過路亽.° 提交于 2019-12-08 14:22:40
I'm pretty new to RxJs and haven't read a solution to this. More detailed explanation is in the comments, but basically I want to process a key combination (I think buffer would do this) when a specific key is pressed (like pressing "o" will wait for a short time for other keys to be pressed), but immediately process the key input otherwise (anything other than "o" if "o" hasn't been pressed, or the 'timeout' for "o" has passed). Observable.fromEvent(document, 'keydown') // Now I want to only continue processing the event if the user pressed "o99" in series, // as in pressed "o", followed by

Angular 4 Shared Service Observable Behavior Subject

谁都会走 提交于 2019-12-08 14:12:11
问题 I have an BehaviorSubject as part of a SharedServices Module that is provided to the AppModule in the Providers section of the module and subscribe to it in the AppComponent. I also subscribe to it in another component that is part of another Module AdminModule but I'm not getting the changes unless I add it to it Providers section of the AppComponent. Why is this? I thought if you add it to the Providers section in the Module and subscribe all subscribers would get the changes? I have to do

Typescript import statements for Rxjs operators

限于喜欢 提交于 2019-12-08 13:00:08
问题 I have one Angular project where things like the RxJs library operators, map,do etc are not imported. There appears to be no wildcard imports in the source. Both my Ionic and Angular projects do: import { Observable } from 'rxjs'; Then I have an Ionic project which complains if I don't explicity state the imports. import 'rxjs/add/operator/map'; import 'rxjs/add/operator/do'; Furthermore in the Ionic project, I can't seem to locate refCount in node_modules folders for RxJS either. Though now,