angular - 为什么 Angular 解析器在使用 of() 返回可观察对象时不返回任何数据,但在使用 of().pipe(delay(1000)) 时返回
问题描述
我的问题就像标题一样。我不完全理解为什么 Angular 解析器在使用创建返回的对象时不返回(不解析)任何数据,of([...someData])
但在使用时工作of([...someData]).pipe(delay(1000)
举一个简单的例子:解析器:
resolve(
route: ActivatedRouteSnapshot,
state: RouterStateSnapshot
):
| Schedule.FetchAllSportTypesSuccess
| Schedule.FetchAllSportTypesFailed
| Observable<Schedule.FetchAllSportTypesSuccess | Schedule.FetchAllSportTypesFailed>
| Promise<Schedule.FetchAllSportTypesSuccess | Schedule.FetchAllSportTypesFailed>
{
this.store.dispatch(new Schedule.FetchAllSportTypes());
const responseOK: Observable<Schedule.FetchAllSportTypesSuccess> = this.actions$.pipe(ofAction(Schedule.FetchAllSportTypesSuccess));
const responseError = this.actions$.pipe(
ofAction(Schedule.FetchAllSportTypesFailed),
tap(() => this.router.navigate(['']))
);
return race(responseOK, responseError).pipe(first());
}
this.store.dispatch(new Schedule.FetchAllSportTypes())
调用fetchAllSportTypes
方法:
fetchAllSportTypes(): Observable<SportType[]>{
}
当实现fetchAllSportTypes(): Observable<SportType[]>
如下时,解析器不返回任何数据,它只是一直等待:
fetchAllSportTypes(): Observable<SportType[]>{
return of([...someData])
}
但是当实现如下时,解析器确实按预期工作:
fetchAllSportTypes(): Observable<SportType[]>{
return of([...someData]).pipe(delay(1000))
}
解决方案
推荐阅读
- react-native - 在 React Native 中使用 React Navigation 在 navigationOptions 中将标头设置为 null?
- javascript - 在Javascript中连接多维数组的最佳方法是什么?
- r - 包'keras'成功安装,但无法加载?
- symfony - 更改浏览器语言或项目语言以测试本地化
- r - `for` 是 R 中的函数吗?
- laravel - 字段 [_id] 是元数据字段,不能添加到文档中。使用索引 API 请求参数
- laravel - 未找到 Laravel Passport Oauth 路由页面
- android - 如何从strings.xml中动态获取图片
- python - 检查某些字符的空字符串时,“不在”身份运算符不起作用
- python - 用梯度下降拟合一条线