import { Injectable } from '@angular/core'; import { Actions, createEffect, ofType } from '@ngrx/effects'; import { of } from 'rxjs'; import { map, switchMap, catchError } from 'rxjs/operators'; import { CommentService } from './comment.service'; import * as CommentActions from './comment.actions'; @Injectable() export class CommentEffects { loadComments$ = createEffect(() => this.actions$.pipe( ofType(CommentActions.loadComments), switchMap(_ => this.api.getAll().pipe( map(data => CommentActions.loadCommentsSuccess({ comments: data as any })), // debug type issue here catchError(_ => of(CommentActions.loadCommentsFailure())) ) ) ) ); constructor( private api: CommentService, private actions$: Actions ) { } }