首页 > 解决方案 > 如何查看 observables 的运行时值

问题描述

考虑以下从路由组件接收参数的类

export class customerEntryPoint  {

readonly customerId$: Observable<string>;

constructor(route: ActivatedRoute) {

this.customerId$ = route.querparams.pipe(
                    filter(params => params.customerId?.length > 0),
                    filter(params => params.customerId))l

console.log(this.customerId$)

问题。上面的代码很好,但问题是我如何使用 console.log 语句查看值,或者他们是查看值运行时间的更好方法

}

标签: angularrxjs

解决方案


tap您可以在所需步骤将控制台日志放入副作用运算符

       route.querparams.pipe(
                filter(params => params.customerId?.length > 0),
                filter(params => params.customerId),
                tap(console.log))

推荐阅读