angular-observable

Observable stops firing even when catching the error

*爱你&永不变心* 提交于 2021-02-08 05:13:00
问题 I'm facing with a very strange behavior on my project, I have a simple Angular service with the below code: seatClick$ = new Subject<Seat>(); and a method on the service that fires the observable: handleSeatClick(seat: Seat) { this.seatClick$.next(seat); } the observable logic is simple: this.seatClick$.pipe( exhaustMap((seat: Seat) => { this.someFunctionThatThrowsException(); // this function throws ref exception return of(null); }) , catchError(err => { console.log('error handled'); return

Angular 9 Service as Obesrvable in library

不想你离开。 提交于 2021-01-29 19:56:24
问题 I am working on multiapplication setup, where inside workspace 2 or 3 applications will share library with common and shared components. Currently, I am adding notifications service. Added (at least for now) as part of library main module. As base I am using this example from stackblitz or this one When calling notification service from inside library (which is inside the same module as notification.component: this._notificationSvc.success('Hello World','This is a success !'); the service

How to wait for subscribe to finish Angular 5?

点点圈 提交于 2021-01-29 07:30:41
问题 I am working on an Angular 5 app. I get an error because I have a function that executes before another function is done, hence getting a null variable. I have tried to use .map and .subscribe with Observable, but didn't succeed. Here is the code: loadData is called from my app.component class : ngOnInit() { this.dataService.loadData(sessionStorage.getItem(...); } While that function executes, another function from data.component class (dataService.getData) is called on initialization:

Angular 5 - Asynchronous Service Calls in two different components (First Method Not waiting for DB response)

↘锁芯ラ 提交于 2021-01-28 18:50:07
问题 I have to perform two different DB transactions on a single (click) event. First Call : Save Data to DB. Second Call : Get the first call's saved data from DB These calls are separated in two different components and deal with one common DB Table. My approach is below : First Component TS : ngOnDestroy(){ this.saveData(); } Second Component TS : ngOnInit(){ this.getSavedData(); } Service call for First Method to Execute : saveData(obj) { return this.http.post(environment.appUrl + 'saveDataApi

How can I call multiple API's on a function with Angular?

六眼飞鱼酱① 提交于 2020-08-26 15:32:01
问题 I need to call 4 different API's on a single function which is need to execute one after another as my previous API result will use the next Call as a param. For example: I have a call API for geo Ip, then I need to call an another API which I need to pass lat and long which I have got from first API call. How can I achieve this task on angular 4? I heard about some methods like flatmap and forkjoin. Is this method can use? (I didn't have any code as I am little bit confused). 回答1: You can do

How can I call multiple API's on a function with Angular?

自作多情 提交于 2020-08-26 15:27:22
问题 I need to call 4 different API's on a single function which is need to execute one after another as my previous API result will use the next Call as a param. For example: I have a call API for geo Ip, then I need to call an another API which I need to pass lat and long which I have got from first API call. How can I achieve this task on angular 4? I heard about some methods like flatmap and forkjoin. Is this method can use? (I didn't have any code as I am little bit confused). 回答1: You can do

Type 'boolean' is not assignable to type 'ObservableInput<{}>'

余生长醉 提交于 2020-01-15 04:40:39
问题 I am working on angular 6 project. I am using canDeactivate for my routeGuards and a popup to show route leave message. But the issue is coming at my price-list-guard-service on hover .flatMap(isAllow)=> { Error: Argument of type '(isAllow: boolean) => boolean' is not assignable to parameter of type '(value: boolean, index: number) => ObservableInput<{}>'.. I wanted to do something like this in price-list-guard.service.ts: price-list-guard.service.ts @Injectable() export class

Angular 4 Observable service not working for an api http get

此生再无相见时 提交于 2020-01-14 06:20:14
问题 Angular 4 Observable service not working for an api http get. The http that returns an observable doesnt seem to work. I'm using the new HttpClient This is the error I get: Error: Cannot find a differ supporting object '[object Object]' of type 'object'. NgFor only supports binding to Iterables such as Arrays. Solution? It doesn't seem to like Observable going to the ngFor. Maybe I need to do a switchMap? in the component. This is my http service call: import { Injectable } from "@angular

Angular HTTP Interceptor subscribing to observable and then returning next.handle but throwing TypeError: You provided 'undefined'

人盡茶涼 提交于 2019-12-24 07:27:27
问题 I have a HTTP interceptor and before every request I check if the access token is expired, if it is, I subscribe to a http.post call from my service and then subscribe to it and when I get a new access token I call next.handle(request) like this: this.auth.refreshAccessToken().subscribe((token: string) => { this.auth.newAccessToken = token; request = request.clone({ setHeaders: { Authorization: `Bearer ${token}` } }); return next.handle(request); }); The issue is then it is throwing TypeError

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