示例来自 ( https://indepth.dev/posts/1518/takeuntildestroy-in-angular-v16 ) 这适用于一种订阅方法,但不适用于两种方法
如果你看下面的代码,那么当组件被销毁时,第二个订阅就会存在。我只是不明白为什么以及如何使代码适用于组件中任意数量的订阅?也许我误解了什么?
import { takeUntilDestroyed } from '@angular/core/rxjs-interop'
constructor(
) {
interval(1000).pipe(
takeUntilDestroyed(),
).subscribe(console.log)
interval(1000).pipe(
takeUntilDestroyed(),
).subscribe(console.log)
}
最佳答案
This issue已fixed随着 16.0.2 的发布!
关于Angular 16 takeUntilDestroyed 运算符具有两种订阅方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76279303/