相关疑难解决方法(0)

不同RxJS科目的语义是什么?

该主题的文档很少,很难在那里发现"入口点".

javascript rxjs rxjs5

18
推荐指数
1
解决办法
1万
查看次数

Angular Observable 使用 takeUntil 销毁:ngOnDestroy 中缺少 .next() 时会发生什么

在 Angular 7 组件中,我使用 RxJS takeUntil() 正确取消订阅可观察订阅。

  • this.destroy$.next()方法中缺少时会发生什么ngOnDestroy(参见下面的示例)?它仍然会正常退订吗?
  • this.destroy$.complete()方法中缺少时会发生什么ngOnDestroy(参见下面的示例)?它仍然会正常退订吗?
  • 有什么方法可以强制使用 takeUntil() 取消订阅的模式被正确使用(例如 tslint 规则、npm 包)?

@Component({
    selector: 'app-flights',
    templateUrl: './flights.component.html'
})
export class FlightsComponent implements OnDestroy, OnInit {
    private readonly destroy$ = new Subject();

    public flights: FlightModel[];

    constructor(private readonly flightService: FlightService) { }

    ngOnInit() {
        this.flightService.getAll()
            .pipe(takeUntil(this.destroy$))
            .subscribe(flights => this.flights = flights);
    }

    ngOnDestroy() {
        this.destroy$.next();
        this.destroy$.complete();
    }
}
Run Code Online (Sandbox Code Playgroud)

unsubscribe observable rxjs angular

5
推荐指数
1
解决办法
4174
查看次数

标签 统计

rxjs ×2

angular ×1

javascript ×1

observable ×1

rxjs5 ×1

unsubscribe ×1