【发布时间】:2020-10-22 09:42:09
【问题描述】:
目前我有一个使用 Angular 8 和 RxJS 6.5.2 的实现,可以在 Google Chrome 上完美运行,但在 Safari 中它返回一个对我来说毫无意义的错误。下面我将分享这个实现的一个片段:
public getLoggedEmployee(): Observable<any> {
if (this.employee) {
return of(this.employee);
}
return this.authenticationService
.getAuthenticatedUser()
.pipe(
tap(user => this.authUser = user),
flatMap(user => this.findOneById(user.id)),
map((employee) => {
this.employee = _.merge(employee.data, { user: this.authUser });
return this.employee;
})
);
}
我怎么说,在 Chrome 中工作正常,但在 Safari 中我有这个错误:
Error: Uncaught (in promise): TypeError: undefined is not an object (evaluating 'user.id')
由于某种原因,flatMap 操作中的user 的值仍然未定义,我无法想象为什么。我检查了项目的 compilerOption 目标,目前使用es5,检查了一些缺少的 Safari 填充,但到目前为止还没有运气。
如果有人有任何想法可以帮助我找到解决方案,我将不胜感激。谢谢。
【问题讨论】:
-
您确定您的服务返回的是有效用户吗?尝试将
console.log(user)放在水龙头中 -
是的,我完全确定,正如我在 Google Chrome 中所说的那样,可以正常工作。