rxjs

How to Check for a NULL Result from an Angular 5 RxJS Observable during Subscription?

自古美人都是妖i 提交于 2021-02-18 15:04:14
问题 With RxJS Observables within Angular this.myService.getEmp(personEmpId).subscribe( result => { this.personName = result.person_name; }, error => { console.log("EE:",error); } ); How can I test if my subscription to this service returns a NULL result, i.e. no record was found at all? I tried adding the error part but this did not fire the console message. At the moment, I seem to be getting the following error message: ERROR TypeError: "result is null" 回答1: You can add a filter before

Merge different HTTP calls which are dependent on each other in RxJS/Angular 6

不羁的心 提交于 2021-02-18 14:52:35
问题 I've been trying to find this answer for a while now, but I, as a new person to RxJS and Angular (2+), am looking for a way to combine the results of two HTTP GET calls. Once one call has finished, a new call has to be done based on that result. The result of the first call will be combined with the second call. Preferably in a property which has an object as type. I have been playing with mergeMap , switchMap and concatMap . According to the documentation and guides these functions should do

Pipe and Tap VS subscribe with ngxs

自闭症网瘾萝莉.ら 提交于 2021-02-18 10:16:06
问题 I am playing around with pipe and subscribe. If I am using pipe with tap, nothing will log in console. If I am using subscribe, it's working. So what I am doing wrong? import { Observable } from 'rxjs'; import { tap, take } from 'rxjs/operators'; this.store.select(state => state.auth.authUser).pipe( take(1), tap((data) => { //Not Working - no console output console.log('[Tap] User Data', data); }) ); this.store.select(state => state.auth.authUser).subscribe((data) => { // Working - user data

Merge two observables, single output

好久不见. 提交于 2021-02-18 09:02:01
问题 Hello guys Im trying to grasp RxJS lib and the whole idea of reactive programming. Im trying to merge two observables into one. First observable contains array of objects DefectImages[] the second observable contains array of strings, which then I convert to array of DefectImages[] . After that I would like to merge these two observables into one. Below my code: const observable = CachedPhotosBuffer.getInstance().asObservable() .pipe( switchMap(data => { return data.map((url) => DefectImage

Merge two observables, single output

妖精的绣舞 提交于 2021-02-18 09:01:41
问题 Hello guys Im trying to grasp RxJS lib and the whole idea of reactive programming. Im trying to merge two observables into one. First observable contains array of objects DefectImages[] the second observable contains array of strings, which then I convert to array of DefectImages[] . After that I would like to merge these two observables into one. Below my code: const observable = CachedPhotosBuffer.getInstance().asObservable() .pipe( switchMap(data => { return data.map((url) => DefectImage

Angular 4 - canActivate observable not invoked

眉间皱痕 提交于 2021-02-18 06:29:13
问题 I am trying to implement canActivate in Angular 2/4 using RxJS observables. I have already read another SO question on this. With the following code, my canActivate method works only once, when the app launches, but hello is never printed again when the isLoggedIn observable triggers new values. canActivate(): Observable<boolean> { return this.authService.isLoggedIn().map(isLoggedIn => { console.log('hello'); if (!isLoggedIn) { this.router.navigate(['/login']); } return isLoggedIn; }).first()

Angular 4 - canActivate observable not invoked

二次信任 提交于 2021-02-18 06:27:47
问题 I am trying to implement canActivate in Angular 2/4 using RxJS observables. I have already read another SO question on this. With the following code, my canActivate method works only once, when the app launches, but hello is never printed again when the isLoggedIn observable triggers new values. canActivate(): Observable<boolean> { return this.authService.isLoggedIn().map(isLoggedIn => { console.log('hello'); if (!isLoggedIn) { this.router.navigate(['/login']); } return isLoggedIn; }).first()

Ngrx effect parallel http call

这一生的挚爱 提交于 2021-02-17 02:09:14
问题 I have an effect that should call two different APIs (API1 and API2). Here's the effect $LoadKpiMission = createEffect(() => this.actions$.pipe( ofType<any>(EKpiActions.GetMissionsByStation), mergeMap(action => this.apiCallsService.getKpi(action.payload, '2016-04-18').pipe( map(trips => ({ type: EKpiActions.GetMissionsSuccess, payload: trips })), catchError(() => EMPTY) ) ) ) ); Here's the structure of the service getKpi(station: number, date: string) { let Kpi = `http://192.168.208.25:8998

Ngrx effect parallel http call

左心房为你撑大大i 提交于 2021-02-17 02:08:09
问题 I have an effect that should call two different APIs (API1 and API2). Here's the effect $LoadKpiMission = createEffect(() => this.actions$.pipe( ofType<any>(EKpiActions.GetMissionsByStation), mergeMap(action => this.apiCallsService.getKpi(action.payload, '2016-04-18').pipe( map(trips => ({ type: EKpiActions.GetMissionsSuccess, payload: trips })), catchError(() => EMPTY) ) ) ) ); Here's the structure of the service getKpi(station: number, date: string) { let Kpi = `http://192.168.208.25:8998

Ngrx effect parallel http call

会有一股神秘感。 提交于 2021-02-17 02:07:34
问题 I have an effect that should call two different APIs (API1 and API2). Here's the effect $LoadKpiMission = createEffect(() => this.actions$.pipe( ofType<any>(EKpiActions.GetMissionsByStation), mergeMap(action => this.apiCallsService.getKpi(action.payload, '2016-04-18').pipe( map(trips => ({ type: EKpiActions.GetMissionsSuccess, payload: trips })), catchError(() => EMPTY) ) ) ) ); Here's the structure of the service getKpi(station: number, date: string) { let Kpi = `http://192.168.208.25:8998