如何更改此异步管道并直接取值?

How to change this async pipe and take value directly?

我的 compomnet.tx 文件有一些商店订阅方法,如下所示。

readonly selectedId$: Observable<string | null> = this.store.select(selectedId)
    .pipe(shareReplayUntil(this.destroySub));

它们通常被声明为变量。但是我需要从它们那里获取当前值并将其传递给同一个 .ts 文件中的另一个方法。

  onScanId() {
      // here I need to take subscribe id
      this.store.dispatch(scanId({ Id: "1" }));
  }

我需要一些专家的帮助来解决这个问题。我更喜欢我可以删除这个只读的东西并将它分配给直接变量,并在 Html 文件中使用它。 目前,我使用异步管道获取价值,{ selectedId$ | async }

是什么阻碍了你做事

  this.selectedId$.pipe(take(1)).subscribe(
    Id => this.store.dispatch(scanId({ Id }))
 )

你使用 take(1) 订阅你的 observable 以获得单个值并忘记它。然后订阅它,获取id并发送