首页 > 解决方案 > RxJS .pipe 在 Safari 上无法正常工作

问题描述

目前我有一个使用 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')

由于某种原因,仍然undefinedflatMap的值,我无法想象为什么。我检查了项目的 compilerOption 目标,目前正在使用,检查了一些缺少的 Safari 的 polyfill,但到目前为止还没有运气。useres5

如果有人有任何想法可以帮助我找到解决方案,我将不胜感激。谢谢。

标签: safariangular8rxjs6

解决方案


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

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


推荐阅读