observable

Observable Map function not running (Angular2, http)

我怕爱的太早我们不能终老 提交于 2019-12-23 08:51:42
问题 Update The issue seems to be that the map function is not run on a "failed" request. This means that if the API I'm talking to returns a 422 Validation Failed error (or other 4xx errors) Angular will treat this as a failure and cause the Observer to run the subscribed error callback, skipping the map function in the process. Is it possible to force Angular to treat certain 4xx errors as successful requests, or force the map function to run even when an Observable returns an error? I have the

Rxjs observable wait until some condition is met

蓝咒 提交于 2019-12-23 07:46:12
问题 I have the following retry logic to retry an operation. It works fine for single request. For multiple on going requests, I would like to wait for existing retry logic to complete before retrying. handleError(errors: Observable<any>) { const retryCountStart: number = 1; // wait if there is any existing operation retrying // once it is complete, continue here return errors .mergeScan<any, any>( (retryCount: any, err: any) => { if (retryCount <= 5) { return Observable.of(retryCount + 1); } }

How to convert an Observable into a BehaviorSubject?

久未见 提交于 2019-12-23 07:41:29
问题 I'm trying to convert an Observable into a BehaviorSubject. Like this: a$ = new Observable() b$ = BehaviorSubject.create(new BehaviorSubject(123), a$) // 🔴 I have also tried: a$ = new Observable() b$ = new BehaviorSubject(a$, 123) // 🔴 And: a$ = new Observable() b$ = a$.asBehaviorSubject(123) // 🔴 And: a$ = new Observable() b$ = a$.pipe( toBehaviorSubject(123) ) // 🔴 But none of these works. For now I have to implement like this: a$ = new Observable() b$ = new BehaviorSubject(123) a$

Angular Dynamic Forms, Async does not work. ERROR Error: Cannot find control with name: 'previousMessage' <= (.key)

橙三吉。 提交于 2019-12-23 06:29:29
问题 I'm trying to generate form with data from api, I did everithing how it is writen in documentation: https://angular.io/guide/dynamic-form andit works with array of question, but when questions coming from api it does'n work, I get this error. I changed a code according to this answer: https://stackoverflow.com/a/48391041 but it still doesn't work. Can you help me out ? :) DynamicFormQuestionComponent.html:9 ERROR Error: Cannot find control with name: 'previousMessage'

issue mixing promises with HttpInterceptor observables?

落花浮王杯 提交于 2019-12-23 05:47:08
问题 I am using the HttpInterceptor to resend requests with a token in case they return a 401. This had worked well before, when I was just taking the cached token. Since the Firebase token does not seem to be automatically refreshed (using forceRefresh though), I am now trying to get a fresh token in realtime in the interceptor class. The problem is that now the request is not being re-send. Here is my full interceptor: export class CustomHttpInterceptor implements HttpInterceptor { constructor

angular2- Observable getting data from list out of order

孤街浪徒 提交于 2019-12-23 05:32:34
问题 for (let i = 0; i < this.data.VirtualHosts.length; i++) { // get the vh this.apiService.findVH(this.data.VirtualHosts[i]) // then add each vhost to data by concat and then convert to json .subscribe((data) => { this.data = data.docs[0] this.jsonData = this.jsonData.concat(this.data) //console.log("AFTER: " + this.jsonData[i]._id) //console.log("Response for getVH: " + JSON.stringify(this.jsonData)) }) } Here, I loop through a list of ID's of VirtualHosts and do a get call (findVH) on every

how to unsubscribe for an observable

独自空忆成欢 提交于 2019-12-23 04:19:14
问题 I have an angular application where I am reading a file and processing it and this processing is part of observable. I have a service which returns the observable an (ngbusy:subscription). I am subscribing to this observable in my component. The observable is assigned to an ngBusy which displays a spinner. Now the spinner keeps spinning even after subscribe is complete. I know we need to unsubscribe to the obervable. But when I unsubscri in the same method where we are subscribing, I don't

How to Subscribe to IObservable Sequence, force completion, and retrieve all data without race conditions

孤街醉人 提交于 2019-12-23 03:45:31
问题 There is a pattern I'm having trouble with when working with observables. I am working with a bluetooth device. I send a message to that device telling it to do something and notify me of the result or results. The device starts sending notifications (could go for 10ms or 20s) I wait for the device to finish sending notifications. sometimes this will be a specific message from the device and sometimes I just won't receive any more messages for a timeout period. I convert the messages to a

Ngx-charts can't load bar charts directly with async pipe in angular

我的未来我决定 提交于 2019-12-23 03:10:04
问题 My problem is similar to this stackoverflow post When I use async pipe to observe data from firebase and show it in chart, I can see the chart but prompt null error in console. Without async pipe, all errors are gone but I can't fetch data (duh it's async data). Help me please. 回答1: Cause This is happening because the component cannot work with null values for results . Why? Async pipe is, as you say, used when you do not want to (or do not need to) subscribe in the component code, but do it

Angular5 http reponse interceptor unable to read status code

岁酱吖の 提交于 2019-12-23 03:01:44
问题 I am trying to intercept http responses and redirect any 401's but the err object below is only returning me the following string. I was expecting to at least find the status code.. 401 - Unauthorized Details: Http failure response for http://localhost:4200/api/foo: 401 Unauthorized I can see in the network tab that a well formed 401 is being returned by the server. Any ideas on how I can read them correctly? intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>>