我需要取消订阅 Ngrx Select 吗

Yeh*_*lam 3 ngrx angular ngrx-store

我有一个如下组件,其中有一个select_property单击时调用的按钮。问题是我不确定在$livevisitors每次点击重新分配之前是否需要以任何方式取消订阅,不确定$livevisitors | async在组件模板中这是否对我有用。

export class LiveComponent{

    livevisitors$: Observable<LiveVisitor[]>;
    selected_property_id: number = 0;

    constructor(
            private store: Store<AppState>
        ) {

        this.livevisitors$ = this.store.select(selectAllLiveVisitors);

    }

    select_property(id){
        this.selected_property_id = id;

        if (id == 0){
            this.livevisitors$ = this.store.select(selectAllLiveVisitors);
        } else {
            this.livevisitors$ = this.store.select(selectLiveVisitorsByPropertyId, {property_id: id});
        }
    }
Run Code Online (Sandbox Code Playgroud)

Gér*_*non 5

异步管道为您订阅和取消订阅。您无需管理手动取消订阅。

来自官方文档

当组件被销毁时,异步管道会自动取消订阅以避免潜在的内存泄漏。