Javascript 将问题传递选择器作为参数键入已调度操作

Javascript 将问题传递选择器作为参数键入已调度操作,javascript,angular,redux,rxjs,ngrx,Javascript,Angular,Redux,Rxjs,Ngrx,我想在as选择器更改值时分派一个操作。因此,我使用订阅传递选择器,以避免传递可观察的 selectedSchedulingsOnPopup$ = this.store.pipe(select(selectSchedulingsByBranch)); this.store.dispatch(new GetDirectionsOnGraph(this.selectedSchedulingsOnPopup$.subscribe())) 我得到这个错误 (property) BranchKpisCo

我想在as选择器更改值时分派一个操作。因此,我使用订阅传递选择器,以避免传递可观察的

selectedSchedulingsOnPopup$ = this.store.pipe(select(selectSchedulingsByBranch));

this.store.dispatch(new GetDirectionsOnGraph(this.selectedSchedulingsOnPopup$.subscribe()))
我得到这个错误

(property) BranchKpisComponent.selectedSchedulingsOnPopup$: Observable<ISchedules>
Argument of type 'Subscription' is not assignable to parameter of type 'ISchedules'.
  Index signature is missing in type 'Subscription'.
(属性)BranchKpisComponent.selectedSchedulingsOnPopup$:可观察
“Subscription”类型的参数不能分配给“IsSchedules”类型的参数。
“订阅”类型中缺少索引签名。

整个代码不正确

this
this.selectedSchedulingsOnPopup$.subscribe()
将返回订阅,而不是值

此外,每次分派操作时,都会创建一个新订阅,这将导致意外行为和内存泄漏

您可以单独订阅一次(例如在
ngOnInit
中)

后来

this.store.dispatch(new GetDirectionsOnGraph(this.selectedSchedulingsOnPopupValue))

注意:不要忘记从
中取消订阅。选择SchedulingsonPopup$
否则会导致内存泄漏

我应该何时取消订阅?这取决于具体情况,通常是NDESTROY
this.store.dispatch(new GetDirectionsOnGraph(this.selectedSchedulingsOnPopupValue))