使用outputToObservable的目的是什么?

问题描述 投票:0回答:1

我理解它将输出或输出引用转换为可观察的。但我们实际上会在哪里使用它呢?将输出参考或输出转换为可观察值有什么好处?它一定有一些用例。

 public countObservable$:Observable<number> = of(89);
  public count:OutputRef<number> = outputFromObservable(this.countObservable$);

  public ngOnInit(): void {
    outputToObservable(this.count).subscribe(value => {
      console.log(value)
    })
   
  }
angular
1个回答
0
投票

outputToObservable
专用于以编程方式访问组件输出的特定用途(即不通过模板)。

它允许您订阅它,就像您可以订阅使用

EventEmitter
装饰器声明的
@Output()
一样。

// Some instance reference to `MyComp`.
const myComp: MyComp;

outputToObservable(this.myComp.instance.nameChange) // Observable<string>
  .pipe(...)
  .subscribe(...);
© www.soinside.com 2019 - 2024. All rights reserved.