Angular会自动取消订阅FormControl.value订阅吗?

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

我正在看这个使用untilDestroyed的代码片段:

      this.control.valueChanges.pipe(untilDestroyed(this)).subscribe(c => {
        this.update.emit(c);
      });
    }

Angular是否会自动取消订阅可用于组件销毁的FormControl.valueChanges,或者我们是否需要运营商?

我问的部分原因是我的理解是Angular会自动取消订阅模板表达式中使用的Observable,所以我想也许它可能有一种“魔术”的方式来为FormControl实例做这件事吗?

angular typescript rxjs angular-reactive-forms angular-forms
1个回答
2
投票

您应该取消订阅ngOnDestroy组件回调。

由于流永远不会关闭,订阅将保留。

© www.soinside.com 2019 - 2024. All rights reserved.