首页 > 解决方案 > 为什么我在使用 ngrx 效果时会收到这个可观察到的警告

问题描述

我有一个使用ngrx 效果的角度应用程序,我正在使用它加载firestore 数据。我目前收到此警告:

您在预期流的位置提供了 '() => ({ type })'。您可以提供 Observable、Promise、Array 或 Iterable。

这是我的ngrx效果

loadVendors$: Observable<Action> = createEffect(() => this.actions$.pipe(
		ofType(fromVendorActions.loadVendors),
		switchMap(() => this.store.select(fromRoot.getRouterState)),
		tap((ev: any)=> console.log('before', ev)),
		switchMap((action:any) => this.vendorService.getVendors(action.state.params.vendorGroupId)),
		tap((ev: any)=> console.log('after', ev)),
		map((vendors: any) => fromVendorActions.loadVendorsSuccess({vendors: vendors})),
		catchError(() => fromVendorActions.loadVendorsFail)
	))

我正在从操作切换,获取我所在页面的参数,然后从我的服务切换到可观察对象以检索一些数据作为可观察对象。

使用 tap() 检查流我似乎得到了我所期望的。警告出现在我正在记录流的 (2) 个水龙头之间的控制台中。数据正在正确加载到商店中,但警告让我很烦。

标签: angularrxjsngrx

解决方案


catchError应该返回一个可观察的:

catchError(() => of(fromVendorActions.loadVendorsFail))

推荐阅读