【问题标题】:RxJS .pipe doesn't working as expected on SafariRxJS .pipe 在 Safari 上无法正常工作
【发布时间】: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 中所说的那样,可以正常工作。

标签: safari angular8 rxjs6


【解决方案1】:

在我的 Safari 中没问题(Catalina 10.15.4,Safari 13.1 15609.1.20.111.8)。

getAuthenticatedUser 中返回一个模拟数据(如of({ id: 1 }))怎么样?错误还会出现吗?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-02
    • 1970-01-01
    • 1970-01-01
    • 2022-07-14
    • 2016-09-15
    • 1970-01-01
    相关资源
    最近更新 更多